-
Notifications
You must be signed in to change notification settings - Fork 990
Expand file tree
/
Copy pathmap_route_command_test.go
More file actions
309 lines (263 loc) · 13.4 KB
/
map_route_command_test.go
File metadata and controls
309 lines (263 loc) · 13.4 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
package isolated
import (
"fmt"
"code.cloudfoundry.org/cli/v8/api/cloudcontroller/ccversion"
. "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("map-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("map-route", "ROUTES", "Map a route to an app"))
})
It("displays command usage to output", func() {
session := helpers.CF("map-route", "--help")
Eventually(session).Should(Say(`NAME:`))
Eventually(session).Should(Say(`map-route - Map a route to an app\n`))
Eventually(session).Should(Say(`\n`))
Eventually(session).Should(Say(`USAGE:`))
Eventually(session).Should(Say(`Map an HTTP route:\n`))
Eventually(session).Should(Say(`cf map-route APP_NAME DOMAIN \[--hostname HOSTNAME\] \[--path PATH\] \[--app-protocol PROTOCOL\] \[--app-port PORT\] \[--option OPTION=VALUE\]\n`))
Eventually(session).Should(Say(`Map a TCP route:\n`))
Eventually(session).Should(Say(`cf map-route APP_NAME DOMAIN \[--port PORT] \[--option OPTION=VALUE\]\n`))
Eventually(session).Should(Say(`\n`))
Eventually(session).Should(Say(`EXAMPLES:`))
Eventually(session).Should(Say(`cf map-route my-app example.com # example.com`))
Eventually(session).Should(Say(`cf map-route my-app example.com --hostname myhost # myhost.example.com`))
Eventually(session).Should(Say(`cf map-route my-app example.com --hostname myhost --path foo # myhost.example.com/foo`))
Eventually(session).Should(Say(`cf map-route my-app example.com --hostname myhost --app-protocol http2 # myhost.example.com`))
Eventually(session).Should(Say(`cf map-route my-app example.com --hostname myhost --app-port 8090 # myhost.example.com`))
Eventually(session).Should(Say(`cf map-route my-app example.com --hostname myhost -o loadbalancing=least-connection # myhost.example.com with a per-route option`))
Eventually(session).Should(Say(`cf map-route my-app example.com -o loadbalancing=hash -o hash_header=My-Hash-Header # use hash-based routing for example.com`))
Eventually(session).Should(Say(`cf map-route my-app example.com --port 5000 # example.com:5000`))
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(`--port\s+Port for the TCP route \(default: random port\)`))
Eventually(session).Should(Say(`--app-protocol\s+\[Beta flag, subject to change\] Protocol for the route destination \(default: http1\).\s+Only applied to HTTP routes`))
Eventually(session).Should(Say(`--app-port\s+\[Beta flag, subject to change\] App port for the route destination \(default: 8080\).\s+Only applied to HTTP routes`))
Eventually(session).Should(Say(`--option, -o\s+Set the value of a per-route option`))
Eventually(session).Should(Say(`\n`))
Eventually(session).Should(Say(`SEE ALSO:`))
Eventually(session).Should(Say(`create-route, routes, unmap-route, update-route`))
Eventually(session).Should(Exit(0))
})
})
When("the environment is not setup correctly", func() {
It("fails with the appropriate errors", func() {
helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "map-route", "app-name", "domain-name")
})
})
When("the environment is set up correctly", func() {
var (
orgName string
spaceName string
domainName string
hostName string
path string
userName string
appName string
options map[string]*string
)
BeforeEach(func() {
appName = helpers.NewAppName()
hostName = helpers.NewHostName()
path = helpers.NewPath()
options = helpers.NewOptions()
orgName = helpers.NewOrgName()
spaceName = helpers.NewSpaceName()
helpers.SetupCF(orgName, spaceName)
userName, _ = helpers.GetCredentials()
helpers.WithHelloWorldApp(func(dir string) {
session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, "push", appName)
Eventually(session).Should(Exit(0))
})
})
When("the http route already exists", func() {
var (
route helpers.Route
)
BeforeEach(func() {
domainName = helpers.DefaultSharedDomain()
route = helpers.NewRoute(spaceName, domainName, hostName, path, options)
route.V7Create()
})
AfterEach(func() {
route.Delete()
})
When("route is already mapped to app", func() {
BeforeEach(func() {
session := helpers.CF("map-route", appName, domainName, "--hostname", route.Host, "--path", route.Path)
Eventually(session).Should(Exit(0))
})
It("exits 0 with helpful message saying that the route is already mapped to the app", func() {
session := helpers.CF("map-route", appName, domainName, "--hostname", route.Host, "--path", route.Path)
Eventually(session).Should(Say(`Mapping route %s.%s%s to app %s in org %s / space %s as %s\.\.\.`, hostName, domainName, path, appName, orgName, spaceName, userName))
Eventually(session).Should(Say(`App '%s' is already mapped to route '%s.%s%s'\. Nothing has been updated\.`, appName, hostName, domainName, path))
Eventually(session).Should(Say(`OK`))
Eventually(session).Should(Exit(0))
})
})
When("route is not yet mapped to the app", func() {
It("maps the route to an app", func() {
session := helpers.CF("map-route", appName, domainName, "--hostname", route.Host, "--path", route.Path)
Eventually(session).Should(Say(`Mapping route %s.%s%s to app %s in org %s / space %s as %s\.\.\.`, hostName, domainName, path, appName, orgName, spaceName, userName))
Eventually(session).Should(Say(`OK`))
Eventually(session).Should(Exit(0))
})
When("destination protocol is provided", func() {
BeforeEach(func() {
helpers.SkipIfVersionLessThan(ccversion.MinVersionHTTP2RoutingV3)
})
It("maps the route to an app", func() {
session := helpers.CF("map-route", appName, domainName, "--hostname", route.Host, "--app-protocol", "http2")
Eventually(session).Should(Say(`Mapping route %s.%s to app %s with protocol http2 in org %s / space %s as %s\.\.\.`, hostName, domainName, appName, orgName, spaceName, userName))
Eventually(session).Should(Say(`OK`))
Eventually(session).Should(Exit(0))
})
})
})
})
When("the tcp route already exists", func() {
var (
domain helpers.Domain
routerGroup helpers.RouterGroup
route helpers.Route
)
BeforeEach(func() {
domainName = helpers.NewDomainName()
domain = helpers.NewDomain("", domainName)
routerGroup = helpers.NewRouterGroup(
helpers.NewRouterGroupName(),
"1024-2048",
)
routerGroup.Create()
domain.CreateWithRouterGroup(routerGroup.Name)
route = helpers.NewTCPRoute(spaceName, domainName, 1082, options)
})
AfterEach(func() {
domain.DeleteShared()
routerGroup.Delete()
})
When("route is already mapped to app", func() {
BeforeEach(func() {
session := helpers.CF("map-route", appName, domainName, "--port", fmt.Sprintf("%d", route.Port))
Eventually(session).Should(Exit(0))
})
It("exits 0 with helpful message saying that the route is already mapped to the app", func() {
session := helpers.CF("map-route", appName, domainName, "--port", fmt.Sprintf("%d", route.Port))
Eventually(session).Should(Say(`Mapping route %s:%d to app %s in org %s / space %s as %s\.\.\.`, domainName, route.Port, appName, orgName, spaceName, userName))
Eventually(session).Should(Say(`App '%s' is already mapped to route '%s:%d'\. Nothing has been updated\.`, appName, domainName, route.Port))
Eventually(session).Should(Say(`OK`))
Eventually(session).Should(Exit(0))
})
})
When("route is not yet mapped to the app", func() {
It("maps the route to an app", func() {
session := helpers.CF("map-route", appName, domainName, "--port", fmt.Sprintf("%d", route.Port))
Eventually(session).Should(Say(`Mapping route %s:%d to app %s in org %s / space %s as %s\.\.\.`, domainName, route.Port, appName, orgName, spaceName, userName))
Eventually(session).Should(Say(`OK`))
Eventually(session).Should(Exit(0))
})
})
When("port is not specified", func() {
It("creates a new route with a random port and maps it to the app", func() {
session := helpers.CF("map-route", appName, domainName)
Eventually(session).Should(Say(`Creating route %s for org %s / space %s as %s\.\.\.`, domainName, orgName, spaceName, userName))
Eventually(session).Should(Say(`OK`))
Eventually(session).Should(Say(`Mapping route %s:[0-9]+ to app %s in org %s / space %s as %s\.\.\.`, domainName, appName, orgName, spaceName, userName))
Eventually(session).Should(Say(`OK`))
Eventually(session).Should(Exit(0))
})
})
})
When("the route does *not* exist", func() {
When("it is an HTTP domain", func() {
BeforeEach(func() {
domainName = helpers.DefaultSharedDomain()
})
It("creates the route and maps it to an app", func() {
session := helpers.CF("map-route", appName, domainName, "--hostname", hostName, "--path", path)
Eventually(session).Should(Say(`Creating route %s.%s%s for org %s / space %s as %s\.\.\.`, hostName, domainName, path, orgName, spaceName, userName))
Eventually(session).Should(Say(`OK`))
Eventually(session).Should(Say(`Mapping route %s.%s%s to app %s in org %s / space %s as %s\.\.\.`, hostName, domainName, path, appName, orgName, spaceName, userName))
Eventually(session).Should(Say(`OK`))
Eventually(session).Should(Exit(0))
})
When("destination protocol is provided", func() {
BeforeEach(func() {
helpers.SkipIfVersionLessThan(ccversion.MinVersionHTTP2RoutingV3)
})
It("maps the route to an app", func() {
session := helpers.CF("map-route", appName, domainName, "--hostname", hostName, "--app-protocol", "http2")
Eventually(session).Should(Say(`Creating route %s.%s for org %s / space %s as %s\.\.\.`, hostName, domainName, orgName, spaceName, userName))
Eventually(session).Should(Say(`OK`))
Eventually(session).Should(Say(`Mapping route %s.%s to app %s with protocol http2 in org %s / space %s as %s\.\.\.`, hostName, domainName, appName, orgName, spaceName, userName))
Eventually(session).Should(Say(`OK`))
Eventually(session).Should(Exit(0))
})
})
Context("when per-route options are provided", func() {
It("creates the route and maps it to an app", func() {
optionLBAlgo := "loadbalancing=hash"
optionHashHeader := "hash_header=X-Header"
optionHashBalance := "hash_balance=1.3"
session := helpers.CF("map-route", appName, domainName, "--hostname", hostName, "--path", path, "--option", optionLBAlgo, "--option", optionHashHeader, "--option", optionHashBalance)
Eventually(session).Should(Say(`Creating route %s.%s%s for org %s / space %s as %s\.\.\.`, hostName, domainName, path, orgName, spaceName, userName))
Eventually(session).Should(Say(`OK`))
Eventually(session).Should(Say(`Mapping route %s.%s%s to app %s in org %s / space %s as %s\.\.\.`, hostName, domainName, path, appName, orgName, spaceName, userName))
Eventually(session).Should(Say(`OK`))
Eventually(session).Should(Exit(0))
})
})
})
When("it is an TCP domain", func() {
var (
domain helpers.Domain
routerGroup helpers.RouterGroup
)
BeforeEach(func() {
domainName = helpers.NewDomainName()
domain = helpers.NewDomain("", domainName)
routerGroup = helpers.NewRouterGroup(
helpers.NewRouterGroupName(),
"1024-2048",
)
routerGroup.Create()
domain.CreateWithRouterGroup(routerGroup.Name)
})
AfterEach(func() {
domain.DeleteShared()
routerGroup.Delete()
})
When("a port is provided", func() {
It("creates the route and maps it to an app", func() {
session := helpers.CF("map-route", appName, domainName, "--port", "1052")
Eventually(session).Should(Say(`Creating route %s:%s for org %s / space %s as %s\.\.\.`, domainName, "1052", orgName, spaceName, userName))
Eventually(session).Should(Say(`OK`))
Eventually(session).Should(Say(`Mapping route %s:%s to app %s in org %s / space %s as %s\.\.\.`, domainName, "1052", appName, orgName, spaceName, userName))
Eventually(session).Should(Say(`OK`))
Eventually(session).Should(Exit(0))
})
})
When("a port is not provided", func() {
It("creates the route and maps it to an app", func() {
session := helpers.CF("map-route", appName, domainName)
Eventually(session).Should(Say(`Creating route %s for org %s / space %s as %s\.\.\.`, domainName, orgName, spaceName, userName))
Eventually(session).Should(Say(`OK`))
Eventually(session).Should(Say(`Mapping route %s:[0-9]+ to app %s in org %s / space %s as %s\.\.\.`, domainName, appName, orgName, spaceName, userName))
Eventually(session).Should(Say(`OK`))
Eventually(session).Should(Exit(0))
})
})
})
})
})
})