-
Notifications
You must be signed in to change notification settings - Fork 989
Expand file tree
/
Copy pathupdate_route_command_test.go
More file actions
222 lines (193 loc) · 9.01 KB
/
update_route_command_test.go
File metadata and controls
222 lines (193 loc) · 9.01 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
package isolated
import (
. "code.cloudfoundry.org/cli/v8/cf/util/testhelpers/matchers"
"code.cloudfoundry.org/cli/v8/integration/helpers"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"
. "github.com/onsi/gomega/gexec"
)
var _ = Describe("update-route command", func() {
Context("Help", func() {
It("appears in cf help -a", func() {
session := helpers.CF("help", "-a")
Eventually(session).Should(Exit(0))
Expect(session).To(HaveCommandInCategoryWithDescription("update-route", "ROUTES", "Update a route by route specific options, e.g. load balancing algorithm"))
})
It("displays the help information", func() {
session := helpers.CF("update-route", "--help")
Eventually(session).Should(Say(`NAME:`))
Eventually(session).Should(Say(`update-route - Update a route by route specific options, e.g. load balancing algorithm\n`))
Eventually(session).Should(Say(`\n`))
Eventually(session).Should(Say(`USAGE:`))
Eventually(session).Should(Say(`Update an existing HTTP route:\n`))
Eventually(session).Should(Say(`cf update-route DOMAIN \[--hostname HOSTNAME\] \[--path PATH\] \[--option OPTION=VALUE\] \[--remove-option OPTION\]\n`))
Eventually(session).Should(Say(`\n`))
Eventually(session).Should(Say(`EXAMPLES:`))
Eventually(session).Should(Say(`cf update-route example.com -o loadbalancing=round-robin`))
Eventually(session).Should(Say(`cf update-route example.com -o loadbalancing=least-connection`))
Eventually(session).Should(Say(`cf update-route example.com -o loadbalancing=hash -o hash_header=My-Hash-Header`))
Eventually(session).Should(Say(`cf update-route example.com -o loadbalancing=hash -o hash_header=My-Hash-Header -o hash_balance=1.3`))
Eventually(session).Should(Say(`cf update-route example.com -r loadbalancing`))
Eventually(session).Should(Say(`cf update-route example.com --hostname myhost --path foo -o loadbalancing=round-robin`))
Eventually(session).Should(Say(`\n`))
Eventually(session).Should(Say(`OPTIONS:`))
Eventually(session).Should(Say(`--hostname, -n\s+Hostname for the HTTP route \(required for shared domains\)`))
Eventually(session).Should(Say(`--path\s+Path for the HTTP route`))
Eventually(session).Should(Say(`--option, -o\s+Set the value of a per-route option`))
Eventually(session).Should(Say(`--remove-option, -r\s+Remove an option with the given name`))
Eventually(session).Should(Say(`\n`))
Eventually(session).Should(Say(`SEE ALSO:`))
Eventually(session).Should(Say(`check-route, domains, map-route, routes, unmap-route`))
Eventually(session).Should(Exit(0))
})
})
When("the environment is not setup correctly", func() {
It("fails with the appropriate errors", func() {
helpers.CheckEnvironmentTargetedCorrectly(true, false, ReadOnlyOrg, "update-route", "some-domain")
})
})
When("the environment is set up correctly", func() {
var (
orgName string
spaceName string
)
BeforeEach(func() {
orgName = helpers.NewOrgName()
spaceName = helpers.NewSpaceName()
helpers.SetupCF(orgName, spaceName)
})
AfterEach(func() {
helpers.QuickDeleteOrg(orgName)
})
When("the space and domain exist", func() {
var (
userName string
domainName string
)
BeforeEach(func() {
domainName = helpers.NewDomainName()
userName, _ = helpers.GetCredentials()
})
When("the route already exists", func() {
var (
domain helpers.Domain
hostname string
option string
path string
)
BeforeEach(func() {
domain = helpers.NewDomain(orgName, domainName)
hostname = "key-lime-pie"
path = "/a"
domain.CreatePrivate()
Eventually(helpers.CF("create-route", domainName, "--hostname", hostname, "--path", path)).Should(Exit(0))
})
AfterEach(func() {
domain.Delete()
})
When("a loadbalancing route option is specified", func() {
It("updates the route and runs to completion without failing", func() {
option = "loadbalancing=round-robin"
session := helpers.CF("update-route", domainName, "--hostname", hostname, "--path", path, "--option", option)
Eventually(session).Should(Say(`Updating route %s\.%s%s for org %s / space %s as %s\.\.\.`, hostname, domainName, path, orgName, spaceName, userName))
Eventually(session).Should(Say(`Route %s\.%s%s has been updated`, hostname, domainName, path))
Eventually(session).Should(Say(`OK`))
Eventually(session).Should(Exit(0))
})
})
When("a hash-based routing is enabled and options are specified", func() {
BeforeEach(func() {
helpers.EnableFeatureFlag("hash_based_routing")
})
AfterEach(func() {
helpers.DisableFeatureFlag("hash_based_routing")
})
It("updates the route and runs to completion without failing", func() {
optionLBAlgo := "loadbalancing=hash"
optionHashHeader := "hash_header=X-Header"
optionHashBalance := "hash_balance=1.3"
session := helpers.CF("update-route", domainName, "--hostname", hostname, "--path", path, "--option", optionLBAlgo, "--option", optionHashHeader, "--option", optionHashBalance)
Eventually(session).Should(Say(`Updating route %s\.%s%s for org %s / space %s as %s\.\.\.`, hostname, domainName, path, orgName, spaceName, userName))
Eventually(session).Should(Say(`Route %s\.%s%s has been updated`, hostname, domainName, path))
Eventually(session).Should(Say(`OK`))
Eventually(session).Should(Exit(0))
})
Context("missing required options for hash-based routing", func() {
It("update fails", func() {
optionLBAlgo := "loadbalancing=hash"
session := helpers.CF("update-route", domainName, "--hostname", hostname, "--path", path, "--option", optionLBAlgo)
Eventually(session.Err).Should(Say(`Hash header must be present when loadbalancing is set to hash`))
Eventually(session).Should(Exit(1))
})
})
Context("with wrong loadbalancing option", func() {
It("update fails", func() {
optionLBAlgo := "loadbalancing=round-robin"
optionHashHeader := "hash_header=X-Header"
optionHashBalance := "hash_balance=1.3"
session := helpers.CF("update-route", domainName, "--hostname", hostname, "--path", path, "--option", optionLBAlgo, "--option", optionHashHeader, "--option", optionHashBalance)
Eventually(session.Err).Should(Say(`Options Hash header can only be set when loadbalancing is hash`))
Eventually(session.Err).Should(Say(`Options Hash balance can only be set when loadbalancing is hash`))
Eventually(session).Should(Exit(1))
})
})
})
When("route options are not specified", func() {
It("gives an error message and fails", func() {
session := helpers.CF("update-route", domainName, "--hostname", hostname, "--path", path)
Eventually(session.Err).Should(Say(`Route option support: 'No options were specified for the update of the Route %s\.%s\%s`, hostname, domainName, path))
Eventually(session).Should(Exit(1))
})
})
When("route options are specified in the wrong format", func() {
It("gives an error message and fails", func() {
session := helpers.CF("update-route", domainName, "--hostname", hostname, "--path", path, "--option", "loadbalancing")
Eventually(session.Err).Should(Say(`Route option '%s' for route with host '%s', domain '%s', and path '%s' was specified incorrectly. Please use key-value pair format key=value.`, "loadbalancing", hostname, domainName, path))
Eventually(session).Should(Say("FAILED"))
Eventually(session).Should(Exit(1))
})
})
})
When("the route does not exist", func() {
var (
domain helpers.Domain
hostname string
option string
)
BeforeEach(func() {
domain = helpers.NewDomain(orgName, domainName)
hostname = "key-lime-pie"
option = "loadbalancing=round-robin"
domain.CreatePrivate()
})
AfterEach(func() {
domain.Delete()
})
It("gives an error message", func() {
session := helpers.CF("update-route", domainName, "--hostname", hostname, "--option", option)
Eventually(session).Should(Say(`Updating route %s\.%s for org %s / space %s as %s\.\.\.`, hostname, domainName, orgName, spaceName, userName))
Eventually(session.Err).Should(Say(`API endpoint not found at`))
Eventually(session).Should(Exit(1))
})
})
})
When("the domain does not exist", func() {
It("gives an error message and exits", func() {
session := helpers.CF("update-route", "some-domain")
Eventually(session.Err).Should(Say(`Domain '%s' not found.`, "some-domain"))
Eventually(session).Should(Say("FAILED"))
Eventually(session).Should(Exit(1))
})
})
When("the domain is not specified", func() {
It("displays error and exits 1", func() {
session := helpers.CF("update-route")
Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `DOMAIN` was not provided\n"))
Eventually(session.Err).Should(Say("\n"))
Eventually(session).Should(Say("NAME:\n"))
Eventually(session).Should(Exit(1))
})
})
})
})