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