Skip to content

Commit 7bf98f3

Browse files
committed
add TestBuild
1 parent 7028eb8 commit 7bf98f3

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

semv_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,42 @@ func TestPreRelease(t *testing.T) {
132132
}
133133
}
134134

135+
func TestBuild(t *testing.T) {
136+
tagCmder = MockedCmd{Out: mixed}
137+
v, err := Latest()
138+
if err != nil {
139+
t.Fatal(err)
140+
}
141+
142+
u := "foobar"
143+
h := "2f994ff"
144+
usernameCmder = MockedCmd{Out: u + "\n"}
145+
latestCommitCmder = MockedCmd{Out: h + "\n"}
146+
147+
tests := []struct {
148+
target string
149+
buildName string
150+
want string
151+
}{
152+
{"major", "", "v13.0.0+" + h + "." + u},
153+
{"major", "foo", "v13.0.0+foo"},
154+
{"minor", "", "v12.346.0+" + h + "." + u},
155+
{"minor", "bar", "v12.346.0+bar"},
156+
{"patch", "", "v12.345.68+" + h + "." + u},
157+
{"patch", "foo-bar", "v12.345.68+foo-bar"},
158+
}
159+
160+
for i, tt := range tests {
161+
vn, err := v.Next(tt.target).Build(tt.buildName)
162+
if err != nil {
163+
t.Fatal(err)
164+
}
165+
if vn.String() != tt.want {
166+
t.Errorf("test[%d]: target = %s; name = %s; Semv = %s; want %s", i, tt.target, tt.buildName, vn, tt.want)
167+
}
168+
}
169+
}
170+
135171
func TestIncrementMajor(t *testing.T) {
136172
tests := []struct {
137173
v *Semv

0 commit comments

Comments
 (0)