github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/v7/isolated/delete_route_command_test.go (about) 1 package isolated 2 3 import ( 4 "regexp" 5 6 . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" 7 8 "code.cloudfoundry.org/cli/integration/helpers" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/gbytes" 12 . "github.com/onsi/gomega/gexec" 13 ) 14 15 var _ = Describe("delete-route command", func() { 16 Context("Help", func() { 17 It("appears in cf help -a", func() { 18 session := helpers.CF("help", "-a") 19 Eventually(session).Should(Exit(0)) 20 Expect(session).To(HaveCommandInCategoryWithDescription("delete-route", "ROUTES", "Delete a route")) 21 }) 22 23 It("displays the help information", func() { 24 session := helpers.CF("delete-route", "--help") 25 Eventually(session).Should(Say(`NAME:`)) 26 Eventually(session).Should(Say(`delete-route - Delete a route\n`)) 27 Eventually(session).Should(Say(`\n`)) 28 29 Eventually(session).Should(Say(`USAGE:`)) 30 Eventually(session).Should(Say(`cf delete-route DOMAIN \[--hostname HOSTNAME\] \[--path PATH\] \[-f\]\n`)) 31 Eventually(session).Should(Say(`\n`)) 32 33 Eventually(session).Should(Say(`EXAMPLES:`)) 34 Eventually(session).Should(Say(`cf delete-route example.com\s+# example.com`)) 35 Eventually(session).Should(Say(`cf delete-route example.com --hostname myhost\s+# myhost.example.com`)) 36 Eventually(session).Should(Say(`cf delete-route example.com --hostname myhost --path foo\s+# myhost.example.com/foo`)) 37 Eventually(session).Should(Say(`\n`)) 38 39 Eventually(session).Should(Say(`OPTIONS:`)) 40 Eventually(session).Should(Say(`-f\s+Force deletion without confirmation`)) 41 Eventually(session).Should(Say(`--hostname, -n\s+Hostname used to identify the HTTP route \(required for shared domains\)`)) 42 Eventually(session).Should(Say(`--path\s+Path used to identify the HTTP route`)) 43 Eventually(session).Should(Say(`\n`)) 44 45 Eventually(session).Should(Say(`SEE ALSO:`)) 46 Eventually(session).Should(Say(`delete-orphaned-routes, routes, unmap-route`)) 47 48 Eventually(session).Should(Exit(0)) 49 }) 50 }) 51 52 When("the environment is not setup correctly", func() { 53 It("fails with the appropriate errors", func() { 54 helpers.CheckEnvironmentTargetedCorrectly(true, false, ReadOnlyOrg, "delete-route", "some-domain") 55 }) 56 }) 57 58 When("the environment is set up correctly", func() { 59 var ( 60 buffer *Buffer 61 orgName string 62 spaceName string 63 domainName string 64 ) 65 66 BeforeEach(func() { 67 buffer = NewBuffer() 68 orgName = helpers.NewOrgName() 69 spaceName = helpers.NewSpaceName() 70 domainName = helpers.NewDomainName() 71 72 helpers.SetupCF(orgName, spaceName) 73 }) 74 75 AfterEach(func() { 76 helpers.QuickDeleteOrg(orgName) 77 }) 78 When("the -f flag is not given", func() { 79 var ( 80 domain helpers.Domain 81 ) 82 83 BeforeEach(func() { 84 domain = helpers.NewDomain(orgName, domainName) 85 domain.CreatePrivate() 86 }) 87 88 AfterEach(func() { 89 domain.Delete() 90 }) 91 92 When("the user enters 'y'", func() { 93 BeforeEach(func() { 94 _, err := buffer.Write([]byte("y\n")) 95 Expect(err).ToNot(HaveOccurred()) 96 97 Eventually(helpers.CF("create-route", domainName)).Should(Exit(0)) 98 }) 99 100 When("the user attempts to delete a route with a private domain", func() { 101 It("it asks for confirmation and deletes the domain", func() { 102 session := helpers.CFWithStdin(buffer, "delete-route", domainName) 103 Eventually(session).Should(Say("This action impacts all apps using this route.")) 104 Eventually(session).Should(Say("Deleting this route will make apps unreachable via this route.")) 105 Eventually(session).Should(Say(`Really delete the route %s\?`, domainName)) 106 Eventually(session).Should(Say(regexp.QuoteMeta(`Deleting route %s...`), domainName)) 107 Eventually(session).Should(Say("OK")) 108 Eventually(session).Should(Exit(0)) 109 110 Expect(string(session.Out.Contents())).NotTo(ContainSubstring("Unable to delete")) 111 }) 112 }) 113 }) 114 115 When("the user enters 'n'", func() { 116 BeforeEach(func() { 117 _, err := buffer.Write([]byte("n\n")) 118 Expect(err).ToNot(HaveOccurred()) 119 }) 120 121 It("it asks for confirmation and does not delete the domain", func() { 122 session := helpers.CFWithStdin(buffer, "delete-route", domainName) 123 Eventually(session).Should(Say("This action impacts all apps using this route.")) 124 Eventually(session).Should(Say("Deleting this route will make apps unreachable via this route.")) 125 Eventually(session).Should(Say(`Really delete the route %s\?`, domainName)) 126 Eventually(session).Should(Say(`'%s' has not been deleted`, domainName)) 127 Consistently(session).ShouldNot(Say("OK")) 128 Eventually(session).Should(Exit(0)) 129 }) 130 }) 131 }) 132 133 When("the -f flag is given", func() { 134 BeforeEach(func() { 135 domainName = helpers.NewDomainName() 136 }) 137 138 When("the route does not exist", func() { 139 var ( 140 domain helpers.Domain 141 ) 142 143 BeforeEach(func() { 144 domain = helpers.NewDomain(orgName, domainName) 145 domain.CreatePrivate() 146 }) 147 148 AfterEach(func() { 149 domain.Delete() 150 }) 151 152 It("warns the user that it has already been deleted and runs to completion without failing", func() { 153 session := helpers.CF("delete-route", domainName, "-f") 154 Eventually(session).Should(Say(`Deleting route %s\.\.\.`, domainName)) 155 Eventually(session).Should(Say(`Unable to delete\. Route with domain '%s' not found\.`, domainName)) 156 Eventually(session).Should(Exit(0)) 157 }) 158 }) 159 160 When("the route exist", func() { 161 When("the domain is private", func() { 162 var domain helpers.Domain 163 164 BeforeEach(func() { 165 domain = helpers.NewDomain(orgName, domainName) 166 domain.Create() 167 }) 168 169 AfterEach(func() { 170 domain.Delete() 171 }) 172 173 When("no flags are used", func() { 174 It("deletes the route", func() { 175 Eventually(helpers.CF("create-route", domainName)).Should(Exit(0)) 176 177 session := helpers.CF("delete-route", domainName, "-f") 178 Eventually(session).Should(Say(`Deleting route %s\.\.\.`, domainName)) 179 Eventually(session).Should(Say(`OK`)) 180 Eventually(session).Should(Exit(0)) 181 182 Expect(string(session.Out.Contents())).NotTo(ContainSubstring("Unable to delete")) 183 184 session = helpers.CF("routes") 185 Consistently(session).ShouldNot(Say(`%s`, domainName)) 186 Eventually(session).Should(Exit(0)) 187 }) 188 }) 189 190 When("passing in a hostname", func() { 191 It("deletes the route with the hostname", func() { 192 hostname := "tiramisu" 193 Eventually(helpers.CF("create-route", domainName, "-n", hostname)).Should(Exit(0)) 194 195 session := helpers.CF("delete-route", domainName, "-n", hostname, "-f") 196 Eventually(session).Should(Say(`Deleting route %s\.%s\.\.\.`, hostname, domainName)) 197 Eventually(session).Should(Say(`OK`)) 198 Eventually(session).Should(Exit(0)) 199 200 Expect(string(session.Out.Contents())).NotTo(ContainSubstring("Unable to delete")) 201 202 session = helpers.CF("routes") 203 Consistently(session).ShouldNot(Say(`%s\s+%s`, hostname, domainName)) 204 Eventually(session).Should(Exit(0)) 205 }) 206 }) 207 208 When("passing in a path", func() { 209 It("deletes the route with the path", func() { 210 path := "/flan" 211 Eventually(helpers.CF("create-route", domainName, "--path", path)).Should(Exit(0)) 212 213 session := helpers.CF("delete-route", domainName, "--path", path, "-f") 214 Eventually(session).Should(Say(`Deleting route %s%s\.\.\.`, domainName, path)) 215 Eventually(session).Should(Say(`OK`)) 216 Eventually(session).Should(Exit(0)) 217 218 Expect(string(session.Out.Contents())).NotTo(ContainSubstring("Unable to delete")) 219 220 session = helpers.CF("routes") 221 Consistently(session).ShouldNot(Say(`%s\s+%s`, domainName, path)) 222 Eventually(session).Should(Exit(0)) 223 }) 224 }) 225 226 When("passing in hostname and path with a leading '/'", func() { 227 It("deletes the route with hostname and path", func() { 228 hostname := "tiramisu" 229 pathString := "/recipes" 230 Eventually(helpers.CF("create-route", domainName, "-n", hostname, "--path", pathString)).Should(Exit(0)) 231 232 session := helpers.CF("delete-route", domainName, "-n", hostname, "--path", pathString, "-f") 233 Eventually(session).Should(Say(`Deleting route %s\.%s%s\.\.\.`, hostname, domainName, pathString)) 234 Eventually(session).Should(Say(`OK`)) 235 Eventually(session).Should(Exit(0)) 236 237 Expect(string(session.Out.Contents())).NotTo(ContainSubstring("Unable to delete")) 238 239 session = helpers.CF("routes") 240 Consistently(session).ShouldNot(Say(`%s\s+%s\s+%s`, hostname, domainName, pathString)) 241 Eventually(session).Should(Exit(0)) 242 }) 243 }) 244 245 When("passing in hostname and path without a leading '/'", func() { 246 It("deletes the route with hostname and path", func() { 247 hostname := "tiramisu" 248 pathString := "more-recipes" 249 Eventually(helpers.CF("create-route", domainName, "-n", hostname, "--path", pathString)).Should(Exit(0)) 250 251 session := helpers.CF("delete-route", domainName, "-n", hostname, "--path", pathString, "-f") 252 Eventually(session).Should(Say(`Deleting route %s\.%s\/%s\.\.\.`, hostname, domainName, pathString)) 253 Eventually(session).Should(Say(`OK`)) 254 Eventually(session).Should(Exit(0)) 255 256 Expect(string(session.Out.Contents())).NotTo(ContainSubstring("Unable to delete")) 257 258 session = helpers.CF("routes") 259 Consistently(session).ShouldNot(Say(`%s\s+%s\s+\/%s`, hostname, domainName, pathString)) 260 Eventually(session).Should(Exit(0)) 261 }) 262 }) 263 264 When("passing in empty hostname and path", func() { 265 It("deletes the route with hostname and path", func() { 266 hostname := "" 267 pathString := "/recipes" 268 Eventually(helpers.CF("create-route", domainName, "-n", hostname, "--path", pathString)).Should(Exit(0)) 269 270 session := helpers.CF("delete-route", domainName, "-n", hostname, "--path", pathString, "-f") 271 Eventually(session).Should(Say(`Deleting route %s%s\.\.\.`, domainName, pathString)) 272 Eventually(session).Should(Say(`OK`)) 273 Eventually(session).Should(Exit(0)) 274 275 Expect(string(session.Out.Contents())).NotTo(ContainSubstring("Unable to delete")) 276 277 session = helpers.CF("routes") 278 Consistently(session).ShouldNot(Say(`%s\s+%s`, domainName, pathString)) 279 Eventually(session).Should(Exit(0)) 280 }) 281 }) 282 283 When("passing in path without specifying a hostname", func() { 284 It("deletes the route with hostname and path", func() { 285 pathString := "/recipes" 286 Eventually(helpers.CF("create-route", domainName, "--path", pathString)).Should(Exit(0)) 287 288 session := helpers.CF("delete-route", domainName, "--path", pathString, "-f") 289 Eventually(session).Should(Say(`Deleting route %s%s\.\.\.`, domainName, pathString)) 290 Eventually(session).Should(Say(`OK`)) 291 Eventually(session).Should(Exit(0)) 292 293 Expect(string(session.Out.Contents())).NotTo(ContainSubstring("Unable to delete")) 294 295 session = helpers.CF("routes") 296 Consistently(session).ShouldNot(Say(`%s\s+%s`, domainName, pathString)) 297 Eventually(session).Should(Exit(0)) 298 }) 299 }) 300 301 }) 302 303 When("the domain is shared", func() { 304 var domain helpers.Domain 305 306 BeforeEach(func() { 307 domain = helpers.NewDomain("", domainName) 308 domain.CreateShared() 309 }) 310 311 AfterEach(func() { 312 domain.DeleteShared() 313 }) 314 315 When("no flags are used", func() { 316 It("fails with a helpful message", func() { 317 session := helpers.CF("delete-route", domainName, "-f") 318 Eventually(session).Should(Say(`Deleting route %s\.\.\.`, domainName)) 319 Eventually(session).Should(Say(`Unable to delete\. Route with domain '%s' not found\.`, domainName)) 320 Eventually(session).Should(Say(`OK`)) 321 Eventually(session).Should(Exit(0)) 322 }) 323 }) 324 325 When("passing in a hostname", func() { 326 It("deletes the route with the hostname", func() { 327 hostname := "tiramisu" 328 Eventually(helpers.CF("create-route", domainName, "-n", hostname)).Should(Exit(0)) 329 330 session := helpers.CF("delete-route", domainName, "-n", hostname, "-f") 331 Eventually(session).Should(Say(`Deleting route %s\.%s\.\.\.`, hostname, domainName)) 332 Eventually(session).Should(Say(`OK`)) 333 Eventually(session).Should(Exit(0)) 334 335 Expect(string(session.Out.Contents())).NotTo(ContainSubstring("Unable to delete")) 336 }) 337 }) 338 339 When("passing in hostname and path with a leading '/'", func() { 340 It("deletes the route with hostname and path", func() { 341 hostname := "tiramisu" 342 pathString := "/recipes" 343 Eventually(helpers.CF("create-route", domainName, "-n", hostname, "--path", pathString)).Should(Exit(0)) 344 345 session := helpers.CF("delete-route", domainName, "-n", hostname, "--path", pathString, "-f") 346 Eventually(session).Should(Say(`Deleting route %s\.%s%s\.\.\.`, hostname, domainName, pathString)) 347 Eventually(session).Should(Say(`OK`)) 348 Eventually(session).Should(Exit(0)) 349 350 Expect(string(session.Out.Contents())).NotTo(ContainSubstring("Unable to delete")) 351 }) 352 }) 353 354 When("passing in hostname and path without a leading '/'", func() { 355 It("deletes the route with hostname and path", func() { 356 hostname := "tiramisu" 357 pathString := "more-recipes" 358 Eventually(helpers.CF("create-route", domainName, "-n", hostname, "--path", pathString)).Should(Exit(0)) 359 360 session := helpers.CF("delete-route", domainName, "-n", hostname, "--path", pathString, "-f") 361 Eventually(session).Should(Say(`Deleting route %s\.%s\/%s\.\.\.`, hostname, domainName, pathString)) 362 Eventually(session).Should(Say(`OK`)) 363 Eventually(session).Should(Exit(0)) 364 365 Expect(string(session.Out.Contents())).NotTo(ContainSubstring("Unable to delete")) 366 }) 367 }) 368 }) 369 }) 370 }) 371 372 When("the domain does not exist", func() { 373 It("displays error and exits 0", func() { 374 session := helpers.CF("delete-route", "some-domain", "-f") 375 Eventually(session).Should(Say("OK")) 376 Eventually(session).Should(Exit(0)) 377 Expect(string(session.Err.Contents())).To(Equal("Domain 'some-domain' not found.\n")) 378 }) 379 }) 380 381 When("the domain is not specified", func() { 382 It("displays error and exits 1", func() { 383 session := helpers.CF("delete-route") 384 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `DOMAIN` was not provided\n")) 385 Eventually(session.Err).Should(Say("\n")) 386 Eventually(session).Should(Say("NAME:\n")) 387 Eventually(session).Should(Exit(1)) 388 }) 389 }) 390 }) 391 })