- Notifications
You must be signed in to change notification settings - Fork 324
/
Copy pathdescribe_test.go
109 lines (91 loc) · 2.65 KB
/
describe_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package git
import (
"path"
"runtime"
"strings"
"testing"
)
funcTestDescribeCommit(t*testing.T) {
t.Parallel()
repo:=createTestRepo(t)
defercleanupTestRepo(t, repo)
describeOpts, err:=DefaultDescribeOptions()
checkFatal(t, err)
formatOpts, err:=DefaultDescribeFormatOptions()
checkFatal(t, err)
commitID, _:=seedTestRepo(t, repo)
commit, err:=repo.LookupCommit(commitID)
checkFatal(t, err)
// No annotated tags can be used to describe master
_, err=commit.Describe(&describeOpts)
checkDescribeNoRefsFound(t, err)
// Fallback
fallback:=describeOpts
fallback.ShowCommitOidAsFallback=true
result, err:=commit.Describe(&fallback)
checkFatal(t, err)
resultStr, err:=result.Format(&formatOpts)
checkFatal(t, err)
compareStrings(t, "473bf77", resultStr)
// Abbreviated
abbreviated:=formatOpts
abbreviated.AbbreviatedSize=2
result, err=commit.Describe(&fallback)
checkFatal(t, err)
resultStr, err=result.Format(&abbreviated)
checkFatal(t, err)
compareStrings(t, "473b", resultStr)
createTestTag(t, repo, commit)
// Exact tag
patternOpts:=describeOpts
patternOpts.Pattern="v[0-9]*"
result, err=commit.Describe(&patternOpts)
checkFatal(t, err)
resultStr, err=result.Format(&formatOpts)
checkFatal(t, err)
compareStrings(t, "v0.0.0", resultStr)
// Pattern no match
patternOpts.Pattern="v[1-9]*"
result, err=commit.Describe(&patternOpts)
checkDescribeNoRefsFound(t, err)
commitID, _=updateReadme(t, repo, "update1")
commit, err=repo.LookupCommit(commitID)
checkFatal(t, err)
// Tag-1
result, err=commit.Describe(&describeOpts)
checkFatal(t, err)
resultStr, err=result.Format(&formatOpts)
checkFatal(t, err)
compareStrings(t, "v0.0.0-1-gd88ef8d", resultStr)
// Strategy: All
describeOpts.Strategy=DescribeAll
result, err=commit.Describe(&describeOpts)
checkFatal(t, err)
resultStr, err=result.Format(&formatOpts)
checkFatal(t, err)
compareStrings(t, "heads/master", resultStr)
repo.CreateBranch("hotfix", commit, false)
// Workdir (branch)
result, err=repo.DescribeWorkdir(&describeOpts)
checkFatal(t, err)
resultStr, err=result.Format(&formatOpts)
checkFatal(t, err)
compareStrings(t, "heads/hotfix", resultStr)
}
funccheckDescribeNoRefsFound(t*testing.T, errerror) {
// The failure happens at wherever we were called, not here
_, file, line, ok:=runtime.Caller(1)
expectedString:="no reference found, cannot describe anything"
if!ok {
t.Fatalf("Unable to get caller")
}
iferr==nil||!strings.Contains(err.Error(), expectedString) {
t.Fatalf(
"%s:%v: was expecting error %v, got %v",
path.Base(file),
line,
expectedString,
err,
)
}
}