forked from goadesign/goa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion_test.go
87 lines (73 loc) · 1.78 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
package version_test
import (
"strconv"
"github.com/goadesign/goa/version"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("version", func() {
var ver string
var build, oldBuild string
BeforeEach(func() {
build = ""
})
JustBeforeEach(func() {
oldBuild = version.Build
if build != "" {
version.Build = build
}
ver = version.String()
version.Build = oldBuild
})
Context("with the default build number", func() {
It("should be properly formatted", func() {
Ω(ver).Should(HavePrefix("v"))
})
It("returns the default version", func() {
Ω(ver).Should(HaveSuffix(".0"))
})
})
Context("with an overridden build number", func() {
BeforeEach(func() {
build = "custom"
})
It("returns the overridden version", func() {
Ω(ver).Should(HaveSuffix("." + build))
})
})
Context("checking compatibility", func() {
var otherVersion string
var compatible bool
var compErr error
JustBeforeEach(func() {
compatible, compErr = version.Compatible(otherVersion)
})
Context("with a version with identical major", func() {
BeforeEach(func() {
otherVersion = "v" + strconv.Itoa(version.Major) + ".12.13"
})
It("returns true", func() {
Ω(compErr).ShouldNot(HaveOccurred())
Ω(compatible).Should(BeTrue())
})
})
Context("with a version with different major", func() {
BeforeEach(func() {
otherVersion = "v99999121299999.1.0"
})
It("returns false", func() {
Ω(compErr).ShouldNot(HaveOccurred())
Ω(compatible).Should(BeFalse())
})
})
Context("with a non version string", func() {
BeforeEach(func() {
otherVersion = "v99999121299999.2"
})
It("returns an error", func() {
Ω(compErr).Should(HaveOccurred())
Ω(compatible).Should(BeFalse())
})
})
})
})