forked from buildpacks/pack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version_test.go
95 lines (71 loc) · 2.36 KB
/
version_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
package api_test
import (
"testing"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
"github.com/buildpacks/pack/internal/api"
h "github.com/buildpacks/pack/testhelpers"
)
func TestAPIVersion(t *testing.T) {
spec.Run(t, "APIVersion", testAPIVersion, spec.Parallel(), spec.Report(report.Terminal{}))
}
func testAPIVersion(t *testing.T, when spec.G, it spec.S) {
when("#Equal", func() {
it("is equal to comparison", func() {
subject := api.MustParse("0.2")
comparison := api.MustParse("0.2")
h.AssertEq(t, subject.Equal(comparison), true)
})
it("is not equal to comparison", func() {
subject := api.MustParse("0.2")
comparison := api.MustParse("0.3")
h.AssertEq(t, subject.Equal(comparison), false)
})
})
when("#SupportsVersion", func() {
when("pre-stable", func() {
it("matching minor value", func() {
subject := api.MustParse("0.2")
comparison := api.MustParse("0.2")
h.AssertEq(t, subject.SupportsVersion(comparison), true)
})
it("subject minor > comparison minor", func() {
subject := api.MustParse("0.2")
comparison := api.MustParse("0.1")
h.AssertEq(t, subject.SupportsVersion(comparison), false)
})
it("subject minor < comparison minor", func() {
subject := api.MustParse("0.1")
comparison := api.MustParse("0.2")
h.AssertEq(t, subject.SupportsVersion(comparison), false)
})
})
when("stable", func() {
it("matching major and minor", func() {
subject := api.MustParse("1.2")
comparison := api.MustParse("1.2")
h.AssertEq(t, subject.SupportsVersion(comparison), true)
})
it("matching major but minor > comparison minor", func() {
subject := api.MustParse("1.2")
comparison := api.MustParse("1.1")
h.AssertEq(t, subject.SupportsVersion(comparison), true)
})
it("matching major but minor < comparison minor", func() {
subject := api.MustParse("1.1")
comparison := api.MustParse("1.2")
h.AssertEq(t, subject.SupportsVersion(comparison), false)
})
it("major < comparison major", func() {
subject := api.MustParse("1.0")
comparison := api.MustParse("2.0")
h.AssertEq(t, subject.SupportsVersion(comparison), false)
})
it("major > comparison major", func() {
subject := api.MustParse("2.0")
comparison := api.MustParse("1.0")
h.AssertEq(t, subject.SupportsVersion(comparison), false)
})
})
})
}