-
Notifications
You must be signed in to change notification settings - Fork 31
/
versions_test.go
110 lines (89 loc) · 3.54 KB
/
versions_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
110
package libbuildpack_test
import (
"fmt"
bp "github.com/cloudfoundry/libbuildpack"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("versions", func() {
Describe("FindMatchingVersion", func() {
var versions []string
BeforeEach(func() {
versions = []string{"1.2.3", "1.2.4", "1.2.2", "1.3.3", "1.3.4", "1.3.2", "2.0.0"}
})
It("returns the greatest version", func() {
ver, err := bp.FindMatchingVersion("x", versions)
Expect(err).NotTo(HaveOccurred())
Expect(ver).To(Equal("2.0.0"))
})
It("returns the greatest version in a minor line", func() {
ver, err := bp.FindMatchingVersion("1.x", versions)
Expect(err).NotTo(HaveOccurred())
Expect(ver).To(Equal("1.3.4"))
})
It("returns the greatest version in a patch line", func() {
ver, err := bp.FindMatchingVersion("1.2.x", versions)
Expect(err).NotTo(HaveOccurred())
Expect(ver).To(Equal("1.2.4"))
})
It("returns the greatest version less than the above", func() {
ver, err := bp.FindMatchingVersion(">=1.2.0, <1.2.4", versions)
Expect(err).NotTo(HaveOccurred())
Expect(ver).To(Equal("1.2.3"))
})
It("returns the greatest version less than the above (without comma)", func() {
ver, err := bp.FindMatchingVersion(">=1.2.0 <1.2.4", versions)
Expect(err).NotTo(HaveOccurred())
Expect(ver).To(Equal("1.2.3"))
})
It("returns the greatest version less or equal than the above (without comma)", func() {
ver, err := bp.FindMatchingVersion(">1.2.0 <=1.2.4", versions)
Expect(err).NotTo(HaveOccurred())
Expect(ver).To(Equal("1.2.4"))
})
It("returns an error if nothing matches", func() {
_, err := bp.FindMatchingVersion("1.4.x", versions)
Expect(err).To(MatchError(fmt.Sprintf("no match found for 1.4.x in %v", versions)))
})
})
Describe("FindMatchingVersions", func() {
var versions []string
BeforeEach(func() {
versions = []string{"1.2.3", "1.2.4", "1.2.2", "1.3.3", "1.3.4", "1.3.2", "2.0.0"}
})
It("returns every version for x, sorted", func() {
vers, err := bp.FindMatchingVersions("x", versions)
Expect(err).NotTo(HaveOccurred())
Expect(vers).To(Equal([]string{"1.2.2", "1.2.3", "1.2.4", "1.3.2", "1.3.3", "1.3.4", "2.0.0"}))
})
It("returns all versions in a minor line, sorted", func() {
vers, err := bp.FindMatchingVersions("1.x", versions)
Expect(err).NotTo(HaveOccurred())
Expect(vers).To(Equal([]string{"1.2.2", "1.2.3", "1.2.4", "1.3.2", "1.3.3", "1.3.4"}))
})
It("returns all versions in a patch line", func() {
vers, err := bp.FindMatchingVersions("1.2.x", versions)
Expect(err).NotTo(HaveOccurred())
Expect(vers).To(Equal([]string{"1.2.2", "1.2.3", "1.2.4"}))
})
It("returns all versions less than the above", func() {
vers, err := bp.FindMatchingVersions(">=1.2.0, <1.2.4", versions)
Expect(err).NotTo(HaveOccurred())
Expect(vers).To(Equal([]string{"1.2.2", "1.2.3"}))
})
It("returns all versions less than the above (without comma)", func() {
vers, err := bp.FindMatchingVersions(">=1.2.0 <1.2.4", versions)
Expect(err).NotTo(HaveOccurred())
Expect(vers).To(Equal([]string{"1.2.2", "1.2.3"}))
})
It("returns all versions less or equal than the above (without comma)", func() {
vers, err := bp.FindMatchingVersions(">1.2.2 <=1.2.4", versions)
Expect(err).NotTo(HaveOccurred())
Expect(vers).To(Equal([]string{"1.2.3", "1.2.4"}))
})
It("returns an error if nothing matches", func() {
_, err := bp.FindMatchingVersions("1.4.x", versions)
Expect(err).To(MatchError(fmt.Sprintf("no match found for 1.4.x in %v", versions)))
})
})
})