github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/v6/isolated/create_route_command_test.go (about) 1 package isolated 2 3 import ( 4 "fmt" 5 6 "code.cloudfoundry.org/cli/integration/helpers" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gbytes" 10 . "github.com/onsi/gomega/gexec" 11 ) 12 13 var _ = Describe("create-route command", func() { 14 Context("Help", func() { 15 It("displays the help information", func() { 16 session := helpers.CF("create-route", "--help") 17 Eventually(session).Should(Say(`NAME:`)) 18 Eventually(session).Should(Say(`create-route - Create a url route in a space for later use\n`)) 19 Eventually(session).Should(Say(`\n`)) 20 21 Eventually(session).Should(Say(`USAGE:`)) 22 Eventually(session).Should(Say(`Create an HTTP route:`)) 23 Eventually(session).Should(Say(`cf create-route SPACE DOMAIN \[--hostname HOSTNAME\] \[--path PATH\]\n`)) 24 Eventually(session).Should(Say(`\n`)) 25 26 Eventually(session).Should(Say(`Create a TCP route:`)) 27 Eventually(session).Should(Say(`cf create-route SPACE DOMAIN \(--port PORT \| --random-port\)\n`)) 28 Eventually(session).Should(Say(`\n`)) 29 30 Eventually(session).Should(Say(`EXAMPLES:`)) 31 Eventually(session).Should(Say(`cf create-route my-space example.com\s+# example.com`)) 32 Eventually(session).Should(Say(`cf create-route my-space example.com --hostname myapp\s+# myapp.example.com`)) 33 Eventually(session).Should(Say(`cf create-route my-space example.com --hostname myapp --path foo\s+# myapp.example.com/foo`)) 34 Eventually(session).Should(Say(`cf create-route my-space example.com --port 5000\s+# example.com:5000\n`)) 35 Eventually(session).Should(Say(`\n`)) 36 37 Eventually(session).Should(Say(`OPTIONS:`)) 38 Eventually(session).Should(Say(`--hostname, -n\s+Hostname for the HTTP route \(required for shared domains\)`)) 39 Eventually(session).Should(Say(`--path\s+Path for the HTTP route`)) 40 Eventually(session).Should(Say(`--port\s+Port for the TCP route`)) 41 Eventually(session).Should(Say(`--random-port\s+Create a random port for the TCP route\n`)) 42 Eventually(session).Should(Say(`\n`)) 43 44 Eventually(session).Should(Say(`SEE ALSO:`)) 45 Eventually(session).Should(Say(`check-route, domains, map-route`)) 46 47 Eventually(session).Should(Exit(0)) 48 }) 49 }) 50 51 Context("Flag Errors", func() { 52 When("--hostname and --port are provided", func() { 53 It("fails with a message about being unable to mix --port with the HTTP route options", func() { 54 session := helpers.CF("create-route", "some-space", "some-domain", "--hostname", "some-host", "--port", "1122") 55 Eventually(session.Err).Should(Say(`Incorrect Usage: The following arguments cannot be used together: --hostname, --port`)) 56 Eventually(session).Should(Exit(1)) 57 }) 58 }) 59 60 When("--hostname and --random-port are provided", func() { 61 It("fails with a message about being unable to mix --random-port with any other options", func() { 62 session := helpers.CF("create-route", "some-space", "some-domain", "--hostname", "some-host", "--random-port") 63 Eventually(session.Err).Should(Say(`Incorrect Usage: The following arguments cannot be used together: --hostname, --random-port`)) 64 Eventually(session).Should(Exit(1)) 65 }) 66 }) 67 68 When("--path and --port are provided", func() { 69 It("fails with a message about being unable to mix --port with the HTTP route options", func() { 70 session := helpers.CF("create-route", "some-space", "some-domain", "--path", "/some-path", "--port", "1111") 71 Eventually(session.Err).Should(Say(`Incorrect Usage: The following arguments cannot be used together: --path, --port`)) 72 Eventually(session).Should(Exit(1)) 73 }) 74 }) 75 76 When("--path and --random-port are provided", func() { 77 It("fails with a message about being unable to mix --random-port with any other options", func() { 78 session := helpers.CF("create-route", "some-space", "some-domain", "--path", "/some-path", "--random-port") 79 Eventually(session.Err).Should(Say(`Incorrect Usage: The following arguments cannot be used together: --path, --random-port`)) 80 Eventually(session).Should(Exit(1)) 81 }) 82 }) 83 84 When("both --port and --random-port are provided", func() { 85 It("fails with a message about being unable to mix --random-port with any other options", func() { 86 session := helpers.CF("create-route", "some-space", "some-domain", "--port", "1121", "--random-port") 87 Eventually(session.Err).Should(Say(`Incorrect Usage: The following arguments cannot be used together: --port, --random-port`)) 88 Eventually(session).Should(Exit(1)) 89 }) 90 }) 91 92 When("the provided port is not valid / parseable", func() { 93 It("fails with an appropriate error", func() { 94 session := helpers.CF("create-route", "some-space", "some-domain", "--port", "ABC") 95 Eventually(session.Err).Should(Say(`Incorrect Usage: invalid argument for flag '--port' \(expected int > 0\)`)) 96 Eventually(session).Should(Exit(1)) 97 }) 98 }) 99 }) 100 101 When("the environment is not setup correctly", func() { 102 When("no API endpoint is set", func() { 103 BeforeEach(func() { 104 helpers.UnsetAPI() 105 }) 106 107 It("fails with no API endpoint set message", func() { 108 session := helpers.CF("create-route", "some-space", "some-domain") 109 Eventually(session).Should(Say(`FAILED`)) 110 Eventually(session.Err).Should(Say(`No API endpoint set\. Use 'cf login' or 'cf api' to target an endpoint\.`)) 111 Eventually(session).Should(Exit(1)) 112 }) 113 }) 114 115 When("not logged in", func() { 116 BeforeEach(func() { 117 helpers.LogoutCF() 118 }) 119 120 It("fails with not logged in message", func() { 121 session := helpers.CF("create-route", "some-space", "some-domain") 122 Eventually(session).Should(Say(`FAILED`)) 123 Eventually(session.Err).Should(Say(`Not logged in\. Use 'cf login' or 'cf login --sso' to log in\.`)) 124 Eventually(session).Should(Exit(1)) 125 }) 126 }) 127 128 When("no organization is targeted", func() { 129 BeforeEach(func() { 130 helpers.ClearTarget() 131 }) 132 133 It("fails with 'no organization targeted' message and exits 1", func() { 134 session := helpers.CF("create-route", "some-space", "some-domain") 135 Eventually(session).Should(Say(`FAILED`)) 136 Eventually(session.Err).Should(Say(`No org targeted, use 'cf target -o ORG' to target an org\.`)) 137 Eventually(session).Should(Exit(1)) 138 }) 139 }) 140 }) 141 142 When("the environment is set up correctly", func() { 143 var ( 144 orgName string 145 spaceName string 146 ) 147 148 BeforeEach(func() { 149 orgName = helpers.NewOrgName() 150 spaceName = helpers.NewSpaceName() 151 152 helpers.SetupCF(orgName, spaceName) 153 }) 154 155 AfterEach(func() { 156 helpers.QuickDeleteOrg(orgName) 157 }) 158 159 When("the space does not exist", func() { 160 It("displays 'space not found' and exits 1", func() { 161 badSpaceName := fmt.Sprintf("%s-1", spaceName) 162 session := helpers.CF("create-route", badSpaceName, "some-domain") 163 Eventually(session).Should(Say(`FAILED`)) 164 Eventually(session.Err).Should(Say(`Space '%s' not found\.`, badSpaceName)) 165 Eventually(session).Should(Exit(1)) 166 }) 167 }) 168 169 When("the space is not specified", func() { 170 It("displays error and exits 1", func() { 171 session := helpers.CF("create-route") 172 Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `SPACE` and `DOMAIN` were not provided\n")) 173 Eventually(session.Err).Should(Say("\n")) 174 Eventually(session).Should(Say("NAME:\n")) 175 Eventually(session).Should(Exit(1)) 176 }) 177 }) 178 179 When("the domain does not exist", func() { 180 It("displays error and exits 1", func() { 181 session := helpers.CF("create-route", spaceName, "some-domain") 182 Eventually(session).Should(Say(`FAILED`)) 183 Eventually(session.Err).Should(Say(`Domain 'some-domain' not found.`)) 184 Eventually(session).Should(Exit(1)) 185 }) 186 }) 187 188 When("the domain is not specified", func() { 189 It("displays error and exits 1", func() { 190 session := helpers.CF("create-route", spaceName) 191 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `DOMAIN` was not provided\n")) 192 Eventually(session.Err).Should(Say("\n")) 193 Eventually(session).Should(Say("NAME:\n")) 194 Eventually(session).Should(Exit(1)) 195 }) 196 }) 197 198 When("the space and domain exist", func() { 199 var ( 200 userName string 201 domainName string 202 ) 203 204 BeforeEach(func() { 205 domainName = helpers.NewDomainName() 206 userName, _ = helpers.GetCredentials() 207 }) 208 209 When("the route already exists", func() { 210 var domain helpers.Domain 211 212 BeforeEach(func() { 213 domain = helpers.NewDomain(orgName, domainName) 214 domain.Create() 215 Eventually(helpers.CF("create-route", spaceName, domainName)).Should(Exit(0)) 216 }) 217 218 AfterEach(func() { 219 domain.Delete() 220 }) 221 222 It("warns the user that it has already been created and runs to completion without failing", func() { 223 session := helpers.CF("create-route", spaceName, domainName) 224 Eventually(session).Should(Say(`Creating route %s for org %s / space %s as %s\.\.\.`, domainName, orgName, spaceName, userName)) 225 Eventually(session.Err).Should(Say(`Route %s already exists\.`, domainName)) 226 Eventually(session).Should(Say(`OK`)) 227 Eventually(session).Should(Exit(0)) 228 }) 229 }) 230 231 When("the route already exists in a different space", func() { 232 var domain helpers.Domain 233 234 BeforeEach(func() { 235 domain = helpers.NewDomain(orgName, domainName) 236 domain.Create() 237 differentSpaceName := helpers.NewSpaceName() 238 helpers.CreateSpace(differentSpaceName) 239 Eventually(helpers.CF("create-route", differentSpaceName, domainName)).Should(Exit(0)) 240 }) 241 242 AfterEach(func() { 243 domain.Delete() 244 }) 245 246 It("warns the user that the route is already in use and then fails", func() { 247 session := helpers.CF("create-route", spaceName, domainName) 248 Eventually(session).Should(Say(`Creating route %s for org %s / space %s as %s\.\.\.`, domainName, orgName, spaceName, userName)) 249 Eventually(session.Err).Should(Say("The app cannot be mapped to route %s because the route exists in a different space.", domainName)) 250 Eventually(session).Should(Say(`FAILED`)) 251 Eventually(session).Should(Exit(1)) 252 }) 253 }) 254 255 When("the route does not already exist", func() { 256 When("the domain is private", func() { 257 var domain helpers.Domain 258 259 BeforeEach(func() { 260 domain = helpers.NewDomain(orgName, domainName) 261 domain.Create() 262 Eventually(helpers.CF("create-route", spaceName, domainName)).Should(Exit(0)) 263 }) 264 265 AfterEach(func() { 266 domain.Delete() 267 }) 268 269 When("no flags are used", func() { 270 It("creates the route", func() { 271 session := helpers.CF("create-route", spaceName, domainName) 272 Eventually(session).Should(Say(`Creating route %s for org %s / space %s as %s\.\.\.`, domainName, orgName, spaceName, userName)) 273 Eventually(session).Should(Exit(0)) 274 }) 275 }) 276 277 When("the path is provided but the hostname is not", func() { 278 var path string 279 280 BeforeEach(func() { 281 path = helpers.PrefixedRandomName("path") 282 }) 283 284 It("creates the route", func() { 285 session := helpers.CF("create-route", spaceName, domainName, "--path", path) 286 Eventually(session).Should(Say(`Creating route %s/%s for org %s / space %s as %s\.\.\.`, domainName, path, orgName, spaceName, userName)) 287 Eventually(session).Should(Exit(0)) 288 }) 289 }) 290 }) 291 292 When("the domain is a shared HTTP domain", func() { 293 var domain helpers.Domain 294 295 BeforeEach(func() { 296 domain = helpers.NewDomain(orgName, domainName) 297 domain.CreateShared() 298 }) 299 300 AfterEach(func() { 301 domain.DeleteShared() 302 }) 303 304 When("no flags are used", func() { 305 When("the domain already has some routes", func() { 306 var hostName string 307 308 BeforeEach(func() { 309 hostName = helpers.PrefixedRandomName("my-host") 310 Eventually(helpers.CF("create-route", spaceName, domainName, "--hostname", hostName)).Should(Exit(0)) 311 }) 312 313 It("fails with error message informing users to provide a port or random-port", func() { 314 session := helpers.CF("create-route", spaceName, domainName) 315 Eventually(session).Should(Say(`Creating route %s for org %s / space %s as %s\.\.\.`, domainName, orgName, spaceName, userName)) 316 Eventually(session).Should(Say(`FAILED`)) 317 Eventually(session.Err).Should(Say(`The route is invalid: host is required for shared-domains`)) 318 Eventually(session).Should(Exit(1)) 319 }) 320 }) 321 322 It("fails with an error message and exits 1", func() { 323 session := helpers.CF("create-route", spaceName, domainName) 324 Eventually(session).Should(Say(`Creating route %s for org %s / space %s as %s\.\.\.`, domainName, orgName, spaceName, userName)) 325 Eventually(session.Err).Should(Say(`The route is invalid: host is required for shared-domains`)) 326 Eventually(session).Should(Exit(1)) 327 }) 328 }) 329 330 When("TCP flag options are provided", func() { 331 It("fails with an error message and exits 1", func() { 332 port := "90230" 333 session := helpers.CF("create-route", spaceName, domainName, "--port", port) 334 Eventually(session).Should(Say(`Creating route %s:%s for org %s / space %s as %s\.\.\.`, domainName, port, orgName, spaceName, userName)) 335 Eventually(session.Err).Should(Say(`Port not allowed in HTTP domain %s`, domainName)) 336 Eventually(session).Should(Exit(1)) 337 }) 338 339 It("fails with an error message and exits 1", func() { 340 session := helpers.CF("create-route", spaceName, domainName, "--random-port") 341 Eventually(session).Should(Say(`Creating route %s for org %s / space %s as %s\.\.\.`, domainName, orgName, spaceName, userName)) 342 Eventually(session.Err).Should(Say(`Port not allowed in HTTP domain %s`, domainName)) 343 Eventually(session).Should(Exit(1)) 344 }) 345 }) 346 347 When("the hostname is provided", func() { 348 var hostName string 349 350 BeforeEach(func() { 351 hostName = helpers.PrefixedRandomName("my-host") 352 }) 353 354 When("no path is provided", func() { 355 It("creates the route", func() { 356 session := helpers.CF("create-route", spaceName, domainName, "--hostname", hostName) 357 Eventually(session).Should(Say(`Creating route %s.%s for org %s / space %s as %s\.\.\.`, hostName, domainName, orgName, spaceName, userName)) 358 Eventually(session).Should(Exit(0)) 359 }) 360 }) 361 362 When("a path is provided", func() { 363 It("creates the route", func() { 364 path := fmt.Sprintf("/%s", helpers.PrefixedRandomName("path")) 365 session := helpers.CF("create-route", spaceName, domainName, "--hostname", hostName, "--path", path) 366 Eventually(session).Should(Say(`Creating route %s.%s%s for org %s / space %s as %s\.\.\.`, hostName, domainName, path, orgName, spaceName, userName)) 367 Eventually(session).Should(Exit(0)) 368 }) 369 }) 370 }) 371 372 When("the hostname is not provided", func() { 373 var path string 374 375 BeforeEach(func() { 376 path = helpers.PrefixedRandomName("path") 377 }) 378 379 When("the path is provided", func() { 380 It("fails with an error message and exits 1", func() { 381 session := helpers.CF("create-route", spaceName, domainName, "--path", path) 382 Eventually(session).Should(Say(`Creating route %s/%s for org %s / space %s as %s\.\.\.`, domainName, path, orgName, spaceName, userName)) 383 Eventually(session.Err).Should(Say(`The route is invalid: host is required for shared-domains`)) 384 Eventually(session).Should(Exit(1)) 385 }) 386 }) 387 }) 388 }) 389 390 When("the domain is a shared TCP domain", func() { 391 var domain helpers.Domain 392 393 BeforeEach(func() { 394 domain = helpers.NewDomain(orgName, domainName) 395 domain.CreateWithRouterGroup(helpers.FindOrCreateTCPRouterGroup(GinkgoParallelNode())) 396 }) 397 398 AfterEach(func() { 399 domain.DeleteShared() 400 }) 401 402 When("HTTP flag options are provided", func() { 403 It("fails with an error message and exits 1", func() { 404 hostName := helpers.PrefixedRandomName("host-") 405 path := helpers.PrefixedRandomName("path-") 406 session := helpers.CF("create-route", spaceName, domainName, "--hostname", hostName, "--path", path) 407 Eventually(session).Should(Say(`Creating route %s.%s/%s for org %s / space %s as %s\.\.\.`, hostName, domainName, path, orgName, spaceName, userName)) 408 Eventually(session.Err).Should(Say(`The route is invalid: For TCP routes you must specify a port or request a random one.`)) 409 Eventually(session).Should(Exit(1)) 410 }) 411 }) 412 413 When("a port is provided", func() { 414 It("creates the route", func() { 415 port := "1025" 416 session := helpers.CF("create-route", spaceName, domainName, "--port", port) 417 Eventually(session).Should(Say(`Creating route %s:%s for org %s / space %s as %s\.\.\.`, domainName, port, orgName, spaceName, userName)) 418 Eventually(session).Should(Exit(0)) 419 }) 420 }) 421 422 When("--random-port is provided", func() { 423 It("creates the route", func() { 424 session := helpers.CF("create-route", spaceName, domainName, "--random-port") 425 Eventually(session).Should(Say(`Creating route %s for org %s / space %s as %s\.\.\.`, domainName, orgName, spaceName, userName)) 426 Eventually(session).Should(Say(`Route %s:\d+ has been created\.`, domainName)) 427 Eventually(session).Should(Exit(0)) 428 }) 429 430 When("there are other routes in the domain we want to create the route with", func() { 431 BeforeEach(func() { 432 session := helpers.CF("create-route", spaceName, domainName, "--random-port") 433 Eventually(session).Should(Say(`Route %s:\d+ has been created\.`, domainName)) 434 Eventually(session).Should(Exit(0)) 435 }) 436 437 It("should determine that the random route does not already exist, and create it", func() { 438 session := helpers.CF("create-route", spaceName, domainName, "--random-port") 439 Eventually(session).Should(Say(`Creating route %s for org %s / space %s as %s\.\.\.`, domainName, orgName, spaceName, userName)) 440 Eventually(session).Should(Say(`Route %s:\d+ has been created\.`, domainName)) 441 Eventually(session).Should(Exit(0)) 442 }) 443 }) 444 }) 445 446 When("no options are provided", func() { 447 It("fails with error message informing users to provide a port or random-port", func() { 448 session := helpers.CF("create-route", spaceName, domainName) 449 Eventually(session).Should(Say(`Creating route %s for org %s / space %s as %s\.\.\.`, domainName, orgName, spaceName, userName)) 450 Eventually(session).Should(Say(`FAILED`)) 451 Eventually(session.Err).Should(Say(`The route is invalid: For TCP routes you must specify a port or request a random one.`)) 452 Eventually(session).Should(Exit(1)) 453 }) 454 455 When("the domain already has some routes", func() { 456 BeforeEach(func() { 457 Eventually(helpers.CF("create-route", spaceName, domainName, "--random-port")).Should(Exit(0)) 458 }) 459 460 It("fails with error message informing users to provide a port or random-port", func() { 461 session := helpers.CF("create-route", spaceName, domainName) 462 Eventually(session).Should(Say(`Creating route %s for org %s / space %s as %s\.\.\.`, domainName, orgName, spaceName, userName)) 463 Eventually(session).Should(Say(`FAILED`)) 464 Eventually(session.Err).Should(Say(`The route is invalid: For TCP routes you must specify a port or request a random one.`)) 465 Eventually(session).Should(Exit(1)) 466 }) 467 }) 468 }) 469 }) 470 }) 471 }) 472 }) 473 })