-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_test.go
87 lines (80 loc) · 2.56 KB
/
git_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
package main_test
import (
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/plumbing/storer"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
git_semver "github.com/srbry/git-semver"
)
var _ = DescribeTable("Find the latest semver tag",
func(tags storer.ReferenceIter, tag string) {
Expect(git_semver.LatestSemverTag(tags)).To(Equal(tag))
},
Entry("It returns that latest semver tag",
storer.NewReferenceSliceIter([]*plumbing.Reference{
plumbing.NewReferenceFromStrings("1.2.1", "hash"),
plumbing.NewReferenceFromStrings("1.1.1", "hash"),
plumbing.NewReferenceFromStrings("1.3.1", "hash"),
}),
"1.3.1"),
Entry("It returns that latest semver tag, ignoring non semvers",
storer.NewReferenceSliceIter([]*plumbing.Reference{
plumbing.NewReferenceFromStrings("1.2.1", "hash"),
plumbing.NewReferenceFromStrings("1.1.1", "hash"),
plumbing.NewReferenceFromStrings("foo", "hash"),
}),
"1.2.1"),
Entry("It returns that latest semver tag, handling 'v' prefixes",
storer.NewReferenceSliceIter([]*plumbing.Reference{
plumbing.NewReferenceFromStrings("1.2.1", "hash"),
plumbing.NewReferenceFromStrings("v3.6.2", "hash"),
plumbing.NewReferenceFromStrings("1.1.1", "hash"),
}),
"v3.6.2"),
Entry("It handles no existing semvers",
storer.NewReferenceSliceIter([]*plumbing.Reference{
plumbing.NewReferenceFromStrings("foo", "hash"),
plumbing.NewReferenceFromStrings("bar", "hash"),
plumbing.NewReferenceFromStrings("baz", "hash"),
}),
""),
)
var _ = Describe("#CommitMessagesSince", func() {
var (
commits = []*object.Commit{
{
Hash: plumbing.NewHash("1111111111111111"),
Message: "first commit",
},
{
Hash: plumbing.NewHash("2222222222222222"),
Message: "second commit",
},
{
Hash: plumbing.NewHash("3333333333333333"),
Message: "third commit",
},
}
commitIter *FakeCommitIter
)
BeforeEach(func() {
commitIter = &FakeCommitIter{Commits: commits}
})
Context("when there is a matching ref", func() {
It("returns the commits up to the matching ref", func() {
commitMessages := git_semver.CommitMessagesSince(commits[1].Hash, commitIter)
Expect(commitMessages).To(Equal([]string{"first commit"}))
})
})
Context("when there is no matching ref", func() {
It("returns all the commits", func() {
commitMessages := git_semver.CommitMessagesSince(plumbing.NewHash("no match"), commitIter)
Expect(commitMessages).To(Equal([]string{
"first commit",
"second commit",
"third commit",
}))
})
})
})