forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminimum_version_check_test.go
More file actions
157 lines (136 loc) · 5.58 KB
/
Copy pathminimum_version_check_test.go
File metadata and controls
157 lines (136 loc) · 5.58 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package command_test
import (
. "code.cloudfoundry.org/cli/command"
"code.cloudfoundry.org/cli/command/commandfakes"
"code.cloudfoundry.org/cli/command/translatableerror"
"code.cloudfoundry.org/cli/util/ui"
"code.cloudfoundry.org/cli/version"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"
)
var _ = Describe("Minimum Version Check", func() {
Describe("MinimumAPIVersionCheck", func() {
minimumVersion := "1.0.0"
Context("current version is greater than min", func() {
It("does not return an error", func() {
currentVersion := "1.0.1"
err := MinimumAPIVersionCheck(currentVersion, minimumVersion)
Expect(err).ToNot(HaveOccurred())
})
})
Context("current version is less than min", func() {
It("does return an error", func() {
currentVersion := "1.0.0-alpha.5"
err := MinimumAPIVersionCheck(currentVersion, minimumVersion)
Expect(err).To(MatchError(translatableerror.MinimumAPIVersionNotMetError{
CurrentVersion: currentVersion,
MinimumVersion: minimumVersion,
}))
})
})
Context("current version is the default version", func() {
It("does not return an error", func() {
err := MinimumAPIVersionCheck(version.DefaultVersion, minimumVersion)
Expect(err).ToNot(HaveOccurred())
})
})
Context("minimum version is empty", func() {
It("does not return an error", func() {
err := MinimumAPIVersionCheck("2.0.0", "")
Expect(err).ToNot(HaveOccurred())
})
})
})
Describe("WarnAPIVersionCheck", func() {
var (
testUI *ui.UI
fakeConfig *commandfakes.FakeConfig
apiVersion string
minCLIVersion string
binaryVersion string
)
BeforeEach(func() {
testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer())
fakeConfig = new(commandfakes.FakeConfig)
apiVersion = "1.2.3"
fakeConfig.APIVersionReturns(apiVersion)
minCLIVersion = "1.0.0"
fakeConfig.MinCLIVersionReturns(minCLIVersion)
})
Context("when checking the cloud controller minimum version warning", func() {
Context("when the CLI version is less than the recommended minimum", func() {
BeforeEach(func() {
binaryVersion = "0.0.0"
fakeConfig.BinaryVersionReturns(binaryVersion)
})
It("displays a recommendation to update the CLI version", func() {
err := WarnAPIVersionCheck(fakeConfig, testUI)
Expect(testUI.Err).To(Say("Cloud Foundry API version %s requires CLI version %s. You are currently on version %s. To upgrade your CLI, please visit: https://github.com/cloudfoundry/cli#downloads", apiVersion, minCLIVersion, binaryVersion))
Expect(err).ToNot(HaveOccurred())
})
})
})
Context("when the CLI version is greater or equal to the recommended minimum", func() {
BeforeEach(func() {
binaryVersion = "1.0.0"
fakeConfig.BinaryVersionReturns(binaryVersion)
})
It("does not display a recommendation to update the CLI version", func() {
err := WarnAPIVersionCheck(fakeConfig, testUI)
Expect(err).ToNot(HaveOccurred())
Expect(testUI.Err).NotTo(Say("Cloud Foundry API version %s requires CLI version %s. You are currently on version %s. To upgrade your CLI, please visit: https://github.com/cloudfoundry/cli#downloads", apiVersion, minCLIVersion, binaryVersion))
})
})
Context("when an error is encountered while parsing the semver versions", func() {
BeforeEach(func() {
fakeConfig.BinaryVersionReturns("&#%")
})
It("does not recommend to update the CLI version", func() {
err := WarnAPIVersionCheck(fakeConfig, testUI)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("No Major.Minor.Patch elements found"))
Expect(testUI.Err).NotTo(Say("Cloud Foundry API version %s requires CLI version %s.", apiVersion, minCLIVersion))
})
})
Context("version contains string", func() {
BeforeEach(func() {
minCLIVersion = "1.0.0"
fakeConfig.MinCLIVersionReturns(minCLIVersion)
binaryVersion = "1.0.0-alpha.5"
fakeConfig.BinaryVersionReturns(binaryVersion)
})
It("does not return an error", func() {
err := WarnAPIVersionCheck(fakeConfig, testUI)
Expect(err).ToNot(HaveOccurred())
Expect(testUI.Err).To(Say("Cloud Foundry API version %s requires CLI version %s. You are currently on version %s. To upgrade your CLI, please visit: https://github.com/cloudfoundry/cli#downloads", apiVersion, minCLIVersion, binaryVersion))
})
})
Context("minimum version is empty", func() {
BeforeEach(func() {
minCLIVersion = ""
fakeConfig.MinCLIVersionReturns(minCLIVersion)
binaryVersion = "1.0.0"
fakeConfig.BinaryVersionReturns(binaryVersion)
})
It("does not return an error", func() {
err := WarnAPIVersionCheck(fakeConfig, testUI)
Expect(err).ToNot(HaveOccurred())
Expect(testUI.Err).NotTo(Say("Cloud Foundry API version %s requires CLI version %s. You are currently on version %s. To upgrade your CLI, please visit: https://github.com/cloudfoundry/cli#downloads", apiVersion, minCLIVersion, binaryVersion))
})
})
Context("when comparing the default versions", func() {
BeforeEach(func() {
minCLIVersion = "1.2.3"
fakeConfig.MinCLIVersionReturns(minCLIVersion)
binaryVersion = version.DefaultVersion
fakeConfig.BinaryVersionReturns(binaryVersion)
})
It("does not return an error", func() {
err := WarnAPIVersionCheck(fakeConfig, testUI)
Expect(err).ToNot(HaveOccurred())
Expect(testUI.Err).NotTo(Say("Cloud Foundry API version %s requires CLI version %s. You are currently on version %s. To upgrade your CLI, please visit: https://github.com/cloudfoundry/cli#downloads", apiVersion, minCLIVersion, binaryVersion))
})
})
})
})