github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/labels_command_test.go (about) 1 package isolated 2 3 import ( 4 "fmt" 5 "regexp" 6 7 "code.cloudfoundry.org/cli/integration/helpers/servicebrokerstub" 8 9 . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" 10 "code.cloudfoundry.org/cli/integration/helpers" 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 . "github.com/onsi/gomega/gbytes" 14 . "github.com/onsi/gomega/gexec" 15 ) 16 17 var _ = Describe("labels command", func() { 18 When("--help flag is set", func() { 19 It("appears in cf help -a", func() { 20 session := helpers.CF("help", "-a") 21 Eventually(session).Should(Exit(0)) 22 Expect(session).To(HaveCommandInCategoryWithDescription("labels", "METADATA", "List all labels (key-value pairs) for an API resource")) 23 }) 24 25 It("Displays command usage", func() { 26 session := helpers.CF("labels", "--help") 27 28 Eventually(session).Should(Say("NAME:")) 29 Eventually(session).Should(Say(`\s+labels - List all labels \(key-value pairs\) for an API resource`)) 30 Eventually(session).Should(Say("USAGE:")) 31 Eventually(session).Should(Say(`\s+cf labels RESOURCE RESOURCE_NAME`)) 32 Eventually(session).Should(Say("EXAMPLES:")) 33 Eventually(session).Should(Say(`\s+cf labels app dora`)) 34 Eventually(session).Should(Say(`\s+cf labels org business`)) 35 Eventually(session).Should(Say(`\s+cf labels buildpack go_buildpack --stack cflinuxfs3`)) 36 Eventually(session).Should(Say("RESOURCES:")) 37 Eventually(session).Should(Say(`\s+app`)) 38 Eventually(session).Should(Say(`\s+buildpack`)) 39 Eventually(session).Should(Say(`\s+domain`)) 40 Eventually(session).Should(Say(`\s+org`)) 41 Eventually(session).Should(Say(`\s+route`)) 42 Eventually(session).Should(Say(`\s+service-broker`)) 43 Eventually(session).Should(Say(`\s+service-offering`)) 44 Eventually(session).Should(Say(`\s+service-plan`)) 45 Eventually(session).Should(Say(`\s+space`)) 46 Eventually(session).Should(Say(`\s+stack`)) 47 Eventually(session).Should(Say("OPTIONS:")) 48 Eventually(session).Should(Say(`\s+--stack, -s\s+Specify stack to disambiguate buildpacks with the same name`)) 49 Eventually(session).Should(Say(`\s+--broker, -b\s+Specify a service broker to disambiguate service offerings or service plans with the same name`)) 50 Eventually(session).Should(Say(`\s+--offering, -e\s+Specify a service offering to disambiguate service plans with the same name`)) 51 Eventually(session).Should(Say("SEE ALSO:")) 52 Eventually(session).Should(Say(`\s+set-label, unset-label`)) 53 Eventually(session).Should(Exit(0)) 54 }) 55 }) 56 57 When("the environment is set up correctly", func() { 58 var ( 59 appName string 60 buildpackName string 61 orgName string 62 spaceName string 63 username string 64 ) 65 66 BeforeEach(func() { 67 orgName = helpers.NewOrgName() 68 buildpackName = helpers.NewBuildpackName() 69 username, _ = helpers.GetCredentials() 70 }) 71 72 Describe("app labels", func() { 73 BeforeEach(func() { 74 spaceName = helpers.NewSpaceName() 75 appName = helpers.PrefixedRandomName("app") 76 helpers.SetupCF(orgName, spaceName) 77 helpers.WithHelloWorldApp(func(appDir string) { 78 Eventually(helpers.CF("push", appName, "-p", appDir, "--no-start")).Should(Exit(0)) 79 }) 80 }) 81 AfterEach(func() { 82 helpers.QuickDeleteOrg(orgName) 83 }) 84 85 When("there are labels set on the application", func() { 86 BeforeEach(func() { 87 session := helpers.CF("set-label", "app", appName, "some-other-key=some-other-value", "some-key=some-value") 88 Eventually(session).Should(Exit(0)) 89 }) 90 91 It("lists the labels", func() { 92 session := helpers.CF("labels", "app", appName) 93 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for app %s in org %s / space %s as %s...\n\n"), appName, orgName, spaceName, username)) 94 Eventually(session).Should(Say(`key\s+value`)) 95 Eventually(session).Should(Say(`some-key\s+some-value`)) 96 Eventually(session).Should(Say(`some-other-key\s+some-other-value`)) 97 Eventually(session).Should(Exit(0)) 98 }) 99 }) 100 101 When("there are no labels set on the application", func() { 102 It("indicates that there are no labels", func() { 103 session := helpers.CF("labels", "app", appName) 104 Eventually(session).Should(Exit(0)) 105 Expect(session).Should(Say(regexp.QuoteMeta("Getting labels for app %s in org %s / space %s as %s...\n\n"), appName, orgName, spaceName, username)) 106 Expect(session).ToNot(Say(`key\s+value`)) 107 Expect(session).Should(Say("No labels found.")) 108 }) 109 }) 110 111 When("the app does not exist", func() { 112 It("displays an error", func() { 113 session := helpers.CF("labels", "app", "non-existent-app") 114 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for app non-existent-app in org %s / space %s as %s...\n\n"), orgName, spaceName, username)) 115 Eventually(session.Err).Should(Say("App 'non-existent-app' not found")) 116 Eventually(session).Should(Say("FAILED")) 117 Eventually(session).Should(Exit(1)) 118 }) 119 }) 120 }) 121 122 Describe("buildpack labels", func() { 123 BeforeEach(func() { 124 helpers.LoginCF() 125 }) 126 127 When("there is exactly one buildpack with a given name", func() { 128 When("the buildpack is not bound to a stack", func() { 129 BeforeEach(func() { 130 helpers.SetupBuildpackWithoutStack(buildpackName) 131 }) 132 AfterEach(func() { 133 session := helpers.CF("delete-buildpack", buildpackName, "-f") 134 Eventually(session).Should(Exit(0)) 135 }) 136 137 It("fails if a non-existent stack is specified", func() { 138 session := helpers.CF("labels", "buildpack", buildpackName, "-s", "bogus-stack") 139 Eventually(session.Err).Should(Say("Buildpack '%s' with stack 'bogus-stack' not found", buildpackName)) 140 Eventually(session).Should(Say("FAILED")) 141 Eventually(session).Should(Exit(1)) 142 }) 143 144 It("fails if the -s is specified without an argument", func() { 145 session := helpers.CF("labels", "buildpack", buildpackName, "-s") 146 Eventually(session.Err).Should(Say("Incorrect Usage:")) 147 Eventually(session).Should(Exit(1)) 148 }) 149 150 It("indicates that there are no labels", func() { 151 session := helpers.CF("labels", "buildpack", buildpackName) 152 Eventually(session).Should(Exit(0)) 153 Expect(session).Should(Say(regexp.QuoteMeta("Getting labels for buildpack %s as %s...\n\n"), buildpackName, username)) 154 Expect(session).ToNot(Say(`key\s+value`)) 155 Expect(session).Should(Say("No labels found.")) 156 }) 157 158 When("there are labels on the buildpack", func() { 159 BeforeEach(func() { 160 session := helpers.CF("set-label", "buildpack", buildpackName, "some-other-key=some-other-value", "some-key=some-value") 161 Eventually(session).Should(Exit(0)) 162 }) 163 164 It("lists the labels when no -s flag is given", func() { 165 session := helpers.CF("labels", "buildpack", buildpackName) 166 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for buildpack %s as %s...\n\n"), buildpackName, username)) 167 Eventually(session).Should(Say(`key\s+value`)) 168 Eventually(session).Should(Say(`some-key\s+some-value`)) 169 Eventually(session).Should(Say(`some-other-key\s+some-other-value`)) 170 Eventually(session).Should(Exit(0)) 171 }) 172 173 It("lists the labels when the -s flag is given with an empty-string", func() { 174 session := helpers.CF("labels", "buildpack", buildpackName, "-s", "") 175 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for buildpack %s as %s...\n\n"), buildpackName, username)) 176 Eventually(session).Should(Say(`key\s+value`)) 177 Eventually(session).Should(Say(`some-key\s+some-value`)) 178 Eventually(session).Should(Say(`some-other-key\s+some-other-value`)) 179 Eventually(session).Should(Exit(0)) 180 }) 181 }) 182 }) 183 184 When("the buildpack is bound to a stack", func() { 185 BeforeEach(func() { 186 helpers.SetupBuildpackWithStack(buildpackName, "cflinuxfs3") 187 session := helpers.CF("set-label", "buildpack", buildpackName, "-s", "cflinuxfs3", "some-other-key=some-other-value", "some-key=some-value") 188 Eventually(session).Should(Exit(0)) 189 }) 190 AfterEach(func() { 191 session := helpers.CF("delete-buildpack", buildpackName, "-f", "-s", "cflinuxfs3") 192 Eventually(session).Should(Exit(0)) 193 }) 194 195 It("lists the labels when no stack is specified", func() { 196 session := helpers.CF("labels", "buildpack", buildpackName) 197 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for buildpack %s as %s...\n\n"), buildpackName, username)) 198 Eventually(session).Should(Say(`key\s+value`)) 199 Eventually(session).Should(Say(`some-key\s+some-value`)) 200 Eventually(session).Should(Say(`some-other-key\s+some-other-value`)) 201 Eventually(session).Should(Exit(0)) 202 }) 203 204 It("lists the labels when the stack is specified", func() { 205 session := helpers.CF("labels", "buildpack", buildpackName, "-s", "cflinuxfs3") 206 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for buildpack %s with stack %s as %s...\n\n"), buildpackName, "cflinuxfs3", username)) 207 Eventually(session).Should(Say(`key\s+value`)) 208 Eventually(session).Should(Say(`some-key\s+some-value`)) 209 Eventually(session).Should(Say(`some-other-key\s+some-other-value`)) 210 Eventually(session).Should(Exit(0)) 211 }) 212 213 It("fails if a non-existent stack is specified", func() { 214 session := helpers.CF("labels", "buildpack", buildpackName, "-s", "bogus-stack") 215 Eventually(session.Err).Should(Say("Buildpack '%s' with stack 'bogus-stack' not found", buildpackName)) 216 Eventually(session).Should(Say("FAILED")) 217 Eventually(session).Should(Exit(1)) 218 }) 219 }) 220 }) 221 222 When("there are multiple buildpacks with the same name", func() { 223 var ( 224 newStackName string 225 ) 226 227 BeforeEach(func() { 228 newStackName = helpers.NewStackName() 229 helpers.CreateStack(newStackName) 230 helpers.SetupBuildpackWithStack(buildpackName, newStackName) 231 helpers.SetupBuildpackWithStack(buildpackName, "cflinuxfs3") 232 session := helpers.CF("set-label", "buildpack", buildpackName, "-s", newStackName, 233 "my-stack-some-other-key=some-other-value", "some-key=some-value") 234 Eventually(session).Should(Exit(0)) 235 session = helpers.CF("set-label", "buildpack", buildpackName, "--stack", "cflinuxfs3", 236 "cfl2=var2", "cfl1=var1") 237 Eventually(session).Should(Exit(0)) 238 }) 239 AfterEach(func() { 240 session := helpers.CF("delete-buildpack", buildpackName, "-f", "-s", "cflinuxfs3") 241 Eventually(session).Should(Exit(0)) 242 session = helpers.CF("delete-buildpack", buildpackName, "-f", "-s", newStackName) 243 Eventually(session).Should(Exit(0)) 244 helpers.DeleteStack(newStackName) 245 }) 246 247 It("fails when no stack is given", func() { 248 session := helpers.CF("labels", "buildpack", buildpackName) 249 Eventually(session.Err).Should(Say(fmt.Sprintf(`Multiple buildpacks named %s found. Specify a stack name by using a '-s' flag.`, buildpackName))) 250 Eventually(session).Should(Say(`FAILED`)) 251 Eventually(session).Should(Exit(1)) 252 }) 253 254 It("fails when an empty-string stack is given", func() { 255 session := helpers.CF("labels", "buildpack", buildpackName, "--stack", "") 256 Eventually(session.Err).Should(Say(fmt.Sprintf(`Multiple buildpacks named %s found. Specify a stack name by using a '-s' flag.`, buildpackName))) 257 Eventually(session).Should(Say(`FAILED`)) 258 Eventually(session).Should(Exit(1)) 259 }) 260 261 It("fails when a non-existent stack is given", func() { 262 session := helpers.CF("labels", "buildpack", buildpackName, "-s", "bogus-stack") 263 Eventually(session.Err).Should(Say("Buildpack '%s' with stack 'bogus-stack' not found", buildpackName)) 264 Eventually(session).Should(Say("FAILED")) 265 Eventually(session).Should(Exit(1)) 266 }) 267 268 It("lists the labels for buildpackName/newStackName", func() { 269 session := helpers.CF("labels", "buildpack", buildpackName, "-s", newStackName) 270 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for buildpack %s with stack %s as %s...\n\n"), buildpackName, newStackName, username)) 271 Eventually(session).Should(Say(`key\s+value`)) 272 Eventually(session).Should(Say(`my-stack-some-other-key\s+some-other-value`)) 273 Eventually(session).Should(Say(`some-key\s+some-value`)) 274 Eventually(session).Should(Exit(0)) 275 }) 276 277 It("lists the labels for buildpackName/cflinuxfs3", func() { 278 session := helpers.CF("labels", "buildpack", buildpackName, "--stack", "cflinuxfs3") 279 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for buildpack %s with stack cflinuxfs3 as %s...\n\n"), buildpackName, username)) 280 Eventually(session).Should(Say(`key\s+value`)) 281 Eventually(session).Should(Say(`cfl1\s+var1`)) 282 Eventually(session).Should(Say(`cfl2\s+var2`)) 283 Eventually(session).Should(Exit(0)) 284 }) 285 286 When("there is also a buildpack with the same name but has no stack", func() { 287 BeforeEach(func() { 288 helpers.SetupBuildpackWithoutStack(buildpackName) 289 session := helpers.CF("set-label", "buildpack", buildpackName, 290 "nostack1=var1", "nostack2=var2") 291 Eventually(session).Should(Exit(0)) 292 293 }) 294 AfterEach(func() { 295 session := helpers.CF("delete-buildpack", buildpackName, "-f") 296 Eventually(session).Should(Exit(0)) 297 }) 298 299 It("lists the labels of the no-stack buildpack when no stack is specified", func() { 300 session := helpers.CF("labels", "buildpack", buildpackName) 301 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for buildpack %s as %s...\n\n"), buildpackName, username)) 302 Eventually(session).Should(Say(`key\s+value`)) 303 Eventually(session).Should(Say(`nostack1\s+var1`)) 304 Eventually(session).Should(Say(`nostack2\s+var2`)) 305 Eventually(session).Should(Exit(0)) 306 }) 307 308 It("fails if a non-existent stack is specified", func() { 309 session := helpers.CF("labels", "buildpack", buildpackName, "-s", "bogus-stack") 310 Eventually(session.Err).Should(Say("Buildpack '%s' with stack 'bogus-stack' not found", buildpackName)) 311 Eventually(session).Should(Say("FAILED")) 312 Eventually(session).Should(Exit(1)) 313 }) 314 }) 315 }) 316 }) 317 318 Describe("domain labels", func() { 319 var ( 320 domainName string 321 domain helpers.Domain 322 ) 323 324 BeforeEach(func() { 325 domainName = helpers.NewDomainName("labels") 326 domain = helpers.NewDomain(orgName, domainName) 327 328 helpers.SetupCFWithOrgOnly(orgName) 329 domain.CreatePrivate() 330 }) 331 332 AfterEach(func() { 333 domain.DeletePrivate() 334 helpers.QuickDeleteOrg(orgName) 335 }) 336 337 When("there are labels set on the domain", func() { 338 BeforeEach(func() { 339 session := helpers.CF("set-label", "domain", domainName, "some-other-key=some-other-value", "some-key=some-value") 340 Eventually(session).Should(Exit(0)) 341 }) 342 343 It("lists the labels", func() { 344 session := helpers.CF("labels", "domain", domainName) 345 Eventually(session).Should(Exit(0)) 346 Expect(session).To(Say(regexp.QuoteMeta("Getting labels for domain %s as %s...\n\n"), domainName, username)) 347 Expect(session).To(Say(`key\s+value`)) 348 Expect(session).To(Say(`some-key\s+some-value`)) 349 Expect(session).To(Say(`some-other-key\s+some-other-value`)) 350 }) 351 }) 352 353 When("there are no labels set on the domain", func() { 354 It("indicates that there are no labels", func() { 355 session := helpers.CF("labels", "domain", domainName) 356 Eventually(session).Should(Exit(0)) 357 Expect(session).To(Say(regexp.QuoteMeta("Getting labels for domain %s as %s...\n\n"), domainName, username)) 358 Expect(session).ToNot(Say(`key\s+value`)) 359 Expect(session).Should(Say("No labels found.")) 360 }) 361 }) 362 363 When("the domain does not exist", func() { 364 It("displays an error", func() { 365 session := helpers.CF("labels", "domain", "non-existent-domain") 366 Eventually(session).Should(Exit(1)) 367 Expect(session).To(Say(regexp.QuoteMeta("Getting labels for domain non-existent-domain as %s...\n\n"), username)) 368 Expect(session.Err).To(Say("Domain 'non-existent-domain' not found")) 369 Expect(session).To(Say("FAILED")) 370 }) 371 }) 372 }) 373 374 Describe("org labels", func() { 375 BeforeEach(func() { 376 helpers.SetupCFWithOrgOnly(orgName) 377 }) 378 AfterEach(func() { 379 helpers.QuickDeleteOrg(orgName) 380 }) 381 382 When("there are labels set on the organization", func() { 383 BeforeEach(func() { 384 session := helpers.CF("set-label", "org", orgName, "some-other-key=some-other-value", "some-key=some-value") 385 Eventually(session).Should(Exit(0)) 386 }) 387 It("lists the labels", func() { 388 session := helpers.CF("labels", "org", orgName) 389 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for org %s as %s...\n\n"), orgName, username)) 390 Eventually(session).Should(Say(`key\s+value`)) 391 Eventually(session).Should(Say(`some-key\s+some-value`)) 392 Eventually(session).Should(Say(`some-other-key\s+some-other-value`)) 393 Eventually(session).Should(Exit(0)) 394 }) 395 }) 396 397 When("there are no labels set on the organization", func() { 398 It("indicates that there are no labels", func() { 399 session := helpers.CF("labels", "org", orgName) 400 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for org %s as %s...\n\n"), orgName, username)) 401 Expect(session).ToNot(Say(`key\s+value`)) 402 Eventually(session).Should(Say("No labels found.")) 403 Eventually(session).Should(Exit(0)) 404 }) 405 }) 406 407 When("the org does not exist", func() { 408 It("displays an error", func() { 409 session := helpers.CF("labels", "org", "non-existent-org") 410 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for org %s as %s...\n\n"), "non-existent-org", username)) 411 Eventually(session.Err).Should(Say("Organization 'non-existent-org' not found")) 412 Eventually(session).Should(Say("FAILED")) 413 Eventually(session).Should(Exit(1)) 414 }) 415 }) 416 }) 417 418 Describe("route labels", func() { 419 var ( 420 routeName string 421 domainName string 422 domain helpers.Domain 423 ) 424 425 BeforeEach(func() { 426 orgName = helpers.NewOrgName() 427 spaceName = helpers.NewSpaceName() 428 helpers.SetupCF(orgName, spaceName) 429 430 domainName = helpers.NewDomainName() 431 domain = helpers.NewDomain(orgName, domainName) 432 domain.Create() 433 Eventually(helpers.CF("create-route", domainName)).Should(Exit(0)) 434 routeName = domainName 435 }) 436 437 AfterEach(func() { 438 Eventually(helpers.CF("delete-route", domainName, "-f")).Should(Exit(0)) 439 domain.Delete() 440 helpers.QuickDeleteOrg(orgName) 441 }) 442 443 When("there are labels set on the route", func() { 444 BeforeEach(func() { 445 session := helpers.CF("set-label", "route", routeName, "some-other-key=some-other-value", "some-key=some-value") 446 Eventually(session).Should(Exit(0)) 447 }) 448 449 It("lists the labels", func() { 450 session := helpers.CF("labels", "route", routeName) 451 Eventually(session).Should(Exit(0)) 452 Expect(session).Should(Say(regexp.QuoteMeta("Getting labels for route %s in org %s / space %s as %s...\n\n"), routeName, orgName, spaceName, username)) 453 Expect(session).To(Say(`key\s+value`)) 454 Expect(session).To(Say(`some-key\s+some-value`)) 455 Expect(session).To(Say(`some-other-key\s+some-other-value`)) 456 }) 457 }) 458 459 When("there are no labels set on the route", func() { 460 It("indicates that there are no labels", func() { 461 session := helpers.CF("labels", "route", routeName) 462 Eventually(session).Should(Exit(0)) 463 Expect(session).Should(Say(regexp.QuoteMeta("Getting labels for route %s in org %s / space %s as %s...\n\n"), routeName, orgName, spaceName, username)) 464 Expect(session).ToNot(Say(`key\s+value`)) 465 Expect(session).Should(Say("No labels found.")) 466 }) 467 }) 468 469 When("the route does not exist", func() { 470 It("displays an error", func() { 471 session := helpers.CF("labels", "route", "non-existent-route.example.com") 472 Eventually(session).Should(Exit(1)) 473 Expect(session).Should(Say(regexp.QuoteMeta("Getting labels for route non-existent-route.example.com in org %s / space %s as %s...\n\n"), orgName, spaceName, username)) 474 Expect(session.Err).To(Say("Domain 'example.com' not found")) 475 Expect(session).To(Say("FAILED")) 476 }) 477 }) 478 }) 479 480 Describe("stack labels", func() { 481 var stackName string 482 483 BeforeEach(func() { 484 stackName = helpers.NewStackName() 485 helpers.LoginCF() 486 helpers.CreateStack(stackName) 487 }) 488 AfterEach(func() { 489 helpers.DeleteStack(stackName) 490 }) 491 492 When("there are labels set on the stack", func() { 493 BeforeEach(func() { 494 session := helpers.CF("set-label", "stack", stackName, "some-other-key=some-other-value", "some-key=some-value") 495 Eventually(session).Should(Exit(0)) 496 }) 497 498 It("lists the labels", func() { 499 session := helpers.CF("labels", "stack", stackName) 500 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for stack %s as %s...\n\n"), stackName, username)) 501 Eventually(session).Should(Say(`key\s+value`)) 502 Eventually(session).Should(Say(`some-key\s+some-value`)) 503 Eventually(session).Should(Say(`some-other-key\s+some-other-value`)) 504 Eventually(session).Should(Exit(0)) 505 }) 506 }) 507 508 When("there are no labels set on the stack", func() { 509 It("indicates that there are no labels", func() { 510 session := helpers.CF("labels", "stack", stackName) 511 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for stack %s as %s...\n\n"), stackName, username)) 512 Expect(session).ToNot(Say(`key\s+value`)) 513 Eventually(session).Should(Say("No labels found.")) 514 Eventually(session).Should(Exit(0)) 515 }) 516 }) 517 518 When("the stack does not exist", func() { 519 It("displays an error", func() { 520 session := helpers.CF("labels", "stack", "non-existent-stack") 521 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for stack %s as %s...\n\n"), "non-existent-stack", username)) 522 Eventually(session.Err).Should(Say("Stack 'non-existent-stack' not found")) 523 Eventually(session).Should(Say("FAILED")) 524 Eventually(session).Should(Exit(1)) 525 }) 526 }) 527 }) 528 529 Describe("space labels", func() { 530 BeforeEach(func() { 531 spaceName = helpers.NewSpaceName() 532 helpers.SetupCF(orgName, spaceName) 533 }) 534 AfterEach(func() { 535 helpers.QuickDeleteOrg(orgName) 536 }) 537 538 When("there are labels set on the space", func() { 539 BeforeEach(func() { 540 session := helpers.CF("set-label", "space", spaceName, "some-other-key=some-other-value", "some-key=some-value") 541 Eventually(session).Should(Exit(0)) 542 }) 543 It("lists the labels", func() { 544 session := helpers.CF("labels", "space", spaceName) 545 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for space %s in org %s as %s...\n\n"), spaceName, orgName, username)) 546 Eventually(session).Should(Say(`key\s+value`)) 547 Eventually(session).Should(Say(`some-key\s+some-value`)) 548 Eventually(session).Should(Say(`some-other-key\s+some-other-value`)) 549 Eventually(session).Should(Exit(0)) 550 }) 551 }) 552 553 When("there are no labels set on the space", func() { 554 It("indicates that there are no labels", func() { 555 session := helpers.CF("labels", "space", spaceName) 556 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for space %s in org %s as %s...\n\n"), spaceName, orgName, username)) 557 Expect(session).ToNot(Say(`key\s+value`)) 558 Eventually(session).Should(Say("No labels found.")) 559 Eventually(session).Should(Exit(0)) 560 }) 561 }) 562 563 When("the space does not exist", func() { 564 It("displays an error", func() { 565 session := helpers.CF("labels", "space", "non-existent-space") 566 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for space %s in org %s as %s...\n\n"), "non-existent-space", orgName, username)) 567 Eventually(session.Err).Should(Say("Space 'non-existent-space' not found")) 568 Eventually(session).Should(Say("FAILED")) 569 Eventually(session).Should(Exit(1)) 570 }) 571 }) 572 }) 573 574 Describe("service-broker labels", func() { 575 var broker *servicebrokerstub.ServiceBrokerStub 576 577 BeforeEach(func() { 578 helpers.LoginCF() 579 580 spaceName = helpers.NewSpaceName() 581 helpers.SetupCF(orgName, spaceName) 582 broker = servicebrokerstub.Register() 583 }) 584 585 AfterEach(func() { 586 helpers.QuickDeleteOrg(orgName) 587 broker.Forget() 588 }) 589 590 When("there are labels set on the service broker", func() { 591 BeforeEach(func() { 592 session := helpers.CF("set-label", "service-broker", broker.Name, "some-other-key=some-other-value") 593 Eventually(session).Should(Exit(0)) 594 595 }) 596 597 It("returns the labels associated with the broker", func() { 598 session := helpers.CF("labels", "service-broker", broker.Name) 599 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for service-broker %s as %s...\n\n"), broker.Name, username)) 600 Eventually(session).Should(Say(`key\s+value`)) 601 Expect(session).To(Say(`some-other-key\s+some-other-value`)) 602 Eventually(session).Should(Exit(0)) 603 }) 604 }) 605 606 When("there are no labels set on the service broker", func() { 607 It("indicates that there are no labels", func() { 608 session := helpers.CF("labels", "service-broker", broker.Name) 609 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for service-broker %s as %s...\n\n"), broker.Name, username)) 610 Expect(session).ToNot(Say(`key\s+value`)) 611 Eventually(session).Should(Say("No labels found.")) 612 Eventually(session).Should(Exit(0)) 613 }) 614 }) 615 616 When("the service broker does not exist", func() { 617 It("displays an error", func() { 618 session := helpers.CF("labels", "service-broker", "non-existent-broker") 619 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for service-broker %s as %s...\n\n"), "non-existent-broker", username)) 620 Eventually(session.Err).Should(Say("Service broker 'non-existent-broker' not found")) 621 Eventually(session).Should(Say("FAILED")) 622 Eventually(session).Should(Exit(1)) 623 }) 624 }) 625 }) 626 627 Describe("service-offering labels", func() { 628 var ( 629 broker *servicebrokerstub.ServiceBrokerStub 630 serviceOfferingName string 631 ) 632 633 BeforeEach(func() { 634 helpers.LoginCF() 635 636 spaceName = helpers.NewSpaceName() 637 helpers.SetupCF(orgName, spaceName) 638 broker = servicebrokerstub.Register() 639 serviceOfferingName = broker.FirstServiceOfferingName() 640 }) 641 642 AfterEach(func() { 643 helpers.QuickDeleteOrg(orgName) 644 broker.Forget() 645 }) 646 647 When("there are labels set on the service offering", func() { 648 BeforeEach(func() { 649 session := helpers.CF("set-label", "service-offering", serviceOfferingName, "some-other-key=some-other-value") 650 Eventually(session).Should(Exit(0)) 651 652 }) 653 654 It("returns the labels associated with the offering", func() { 655 session := helpers.CF("labels", "service-offering", serviceOfferingName) 656 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for service-offering %s as %s...\n\n"), serviceOfferingName, username)) 657 Eventually(session).Should(Say(`key\s+value`)) 658 Expect(session).To(Say(`some-other-key\s+some-other-value`)) 659 Eventually(session).Should(Exit(0)) 660 }) 661 662 When("the service broker is specified", func() { 663 It("returns the labels associated with the offering", func() { 664 session := helpers.CF("labels", "-b", broker.Name, "service-offering", serviceOfferingName) 665 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for service-offering %s from service broker %s as %s...\n\n"), serviceOfferingName, broker.Name, username)) 666 Eventually(session).Should(Say(`key\s+value`)) 667 Expect(session).To(Say(`some-other-key\s+some-other-value`)) 668 Eventually(session).Should(Exit(0)) 669 }) 670 }) 671 }) 672 673 When("there are no labels set on the service offering", func() { 674 It("indicates that there are no labels", func() { 675 session := helpers.CF("labels", "service-offering", serviceOfferingName) 676 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for service-offering %s as %s...\n\n"), serviceOfferingName, username)) 677 Expect(session).ToNot(Say(`key\s+value`)) 678 Eventually(session).Should(Say("No labels found.")) 679 Eventually(session).Should(Exit(0)) 680 }) 681 }) 682 683 When("the service offering does not exist", func() { 684 It("displays an error", func() { 685 session := helpers.CF("labels", "service-offering", "non-existent-offering") 686 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for service-offering non-existent-offering as %s...\n\n"), username)) 687 Eventually(session.Err).Should(Say("Service offering 'non-existent-offering' not found")) 688 Eventually(session).Should(Say("FAILED")) 689 Eventually(session).Should(Exit(1)) 690 }) 691 }) 692 }) 693 694 Describe("service-plan labels", func() { 695 var ( 696 broker *servicebrokerstub.ServiceBrokerStub 697 servicePlanName string 698 serviceOfferingName string 699 ) 700 701 BeforeEach(func() { 702 helpers.LoginCF() 703 704 spaceName = helpers.NewSpaceName() 705 helpers.SetupCF(orgName, spaceName) 706 broker = servicebrokerstub.Register() 707 servicePlanName = broker.FirstServicePlanName() 708 serviceOfferingName = broker.FirstServiceOfferingName() 709 }) 710 711 AfterEach(func() { 712 helpers.QuickDeleteOrg(orgName) 713 broker.Forget() 714 }) 715 716 When("there are labels set on the service plan", func() { 717 BeforeEach(func() { 718 session := helpers.CF("set-label", "service-plan", servicePlanName, "some-other-key=some-other-value") 719 Eventually(session).Should(Exit(0)) 720 }) 721 722 It("returns the labels associated with the plan", func() { 723 session := helpers.CF("labels", "service-plan", servicePlanName) 724 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for service-plan %s as %s...\n\n"), servicePlanName, username)) 725 Eventually(session).Should(Say(`key\s+value`)) 726 Expect(session).To(Say(`some-other-key\s+some-other-value`)) 727 Eventually(session).Should(Exit(0)) 728 }) 729 730 When("the service offering and service broker are specified", func() { 731 It("returns the labels associated with the plan", func() { 732 session := helpers.CF("labels", "-e", serviceOfferingName, "-b", broker.Name, "service-plan", servicePlanName) 733 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for service-plan %s from service offering %s / service broker %s as %s..."), servicePlanName, serviceOfferingName, broker.Name, username)) 734 Eventually(session).Should(Say(`key\s+value`)) 735 Expect(session).To(Say(`some-other-key\s+some-other-value`)) 736 Eventually(session).Should(Exit(0)) 737 }) 738 }) 739 }) 740 741 When("there are no labels set on the service plan", func() { 742 It("indicates that there are no labels", func() { 743 session := helpers.CF("labels", "service-plan", servicePlanName) 744 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for service-plan %s as %s...\n\n"), servicePlanName, username)) 745 Expect(session).ToNot(Say(`key\s+value`)) 746 Eventually(session).Should(Say("No labels found.")) 747 Eventually(session).Should(Exit(0)) 748 }) 749 }) 750 751 When("the service plan does not exist", func() { 752 It("displays an error", func() { 753 session := helpers.CF("labels", "service-plan", "non-existent-plan") 754 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for service-plan non-existent-plan as %s...\n\n"), username)) 755 Eventually(session.Err).Should(Say("Service plan 'non-existent-plan' not found")) 756 Eventually(session).Should(Say("FAILED")) 757 Eventually(session).Should(Exit(1)) 758 }) 759 }) 760 }) 761 }) 762 })