github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/integration/v7/isolated/unset_label_command_test.go (about) 1 package isolated 2 3 import ( 4 "fmt" 5 "regexp" 6 7 . "github.com/LukasHeimann/cloudfoundrycli/v8/cf/util/testhelpers/matchers" 8 "github.com/LukasHeimann/cloudfoundrycli/v8/integration/helpers" 9 "github.com/LukasHeimann/cloudfoundrycli/v8/integration/helpers/servicebrokerstub" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 . "github.com/onsi/gomega/gbytes" 13 . "github.com/onsi/gomega/gexec" 14 ) 15 16 var _ = Describe("unset-label command", func() { 17 When("--help flag is set", func() { 18 It("appears in cf help -a", func() { 19 session := helpers.CF("help", "-a") 20 Eventually(session).Should(Exit(0)) 21 Expect(session).To(HaveCommandInCategoryWithDescription("unset-label", "METADATA", "Unset a label (key-value pairs) for an API resource")) 22 }) 23 24 It("Displays command usage to output", func() { 25 session := helpers.CF("unset-label", "--help") 26 27 Eventually(session).Should(Say("NAME:")) 28 Eventually(session).Should(Say(`\s+unset-label - Unset a label \(key-value pairs\) for an API resource`)) 29 Eventually(session).Should(Say("USAGE:")) 30 Eventually(session).Should(Say(`\s+cf unset-label RESOURCE RESOURCE_NAME KEY...`)) 31 Eventually(session).Should(Say("EXAMPLES:")) 32 Eventually(session).Should(Say(`\s+cf unset-label app dora ci_signature_sha2`)) 33 Eventually(session).Should(Say(`\s+cf unset-label org business pci public-facing`)) 34 Eventually(session).Should(Say(`\s+cf unset-label buildpack go_buildpack go -s cflinuxfs3`)) 35 Eventually(session).Should(Say("RESOURCES:")) 36 Eventually(session).Should(Say(`\s+app`)) 37 Eventually(session).Should(Say(`\s+buildpack`)) 38 Eventually(session).Should(Say(`\s+domain`)) 39 Eventually(session).Should(Say(`\s+org`)) 40 Eventually(session).Should(Say(`\s+route`)) 41 Eventually(session).Should(Say(`\s+service-broker`)) 42 Eventually(session).Should(Say(`\s+service-instance`)) 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+labels, set-label`)) 53 Eventually(session).Should(Exit(0)) 54 }) 55 }) 56 57 When("the environment is set up correctly", func() { 58 var ( 59 orgName string 60 spaceName string 61 username string 62 ) 63 64 BeforeEach(func() { 65 username, _ = helpers.GetCredentials() 66 helpers.LoginCF() 67 orgName = helpers.NewOrgName() 68 }) 69 70 When("unsetting labels from an app", func() { 71 var appName string 72 73 BeforeEach(func() { 74 spaceName = helpers.NewSpaceName() 75 appName = helpers.PrefixedRandomName("app") 76 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 session := helpers.CF("set-label", "app", appName, "some-key=some-value", "some-other-key=some-other-value", "some-third-key=other") 83 Eventually(session).Should(Exit(0)) 84 }) 85 AfterEach(func() { 86 helpers.QuickDeleteOrg(orgName) 87 }) 88 89 It("unsets the specified labels on the app", func() { 90 session := helpers.CF("unset-label", "app", appName, "some-other-key", "some-third-key") 91 Eventually(session).Should(Exit(0)) 92 Expect(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for app %s in org %s / space %s as %s...`), appName, orgName, spaceName, username)) 93 Expect(session).Should(Say("OK")) 94 95 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/apps/%s", helpers.AppGUID(appName)), false, helpers.MetadataLabels{ 96 "some-key": "some-value", 97 }) 98 }) 99 }) 100 101 When("unsetting labels from a buildpack", func() { 102 var ( 103 buildpackName string 104 buildpackGUID string 105 stacks []string 106 ) 107 BeforeEach(func() { 108 helpers.LoginCF() 109 buildpackName = helpers.NewBuildpackName() 110 }) 111 112 When("there is only one instance of the given buildpack", func() { 113 114 BeforeEach(func() { 115 stacks = helpers.FetchStacks() 116 helpers.BuildpackWithStack(func(buildpackPath string) { 117 session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "98") 118 Eventually(session).Should(Exit(0)) 119 }, stacks[0]) 120 buildpackGUID = helpers.BuildpackGUIDByNameAndStack(buildpackName, stacks[0]) 121 session := helpers.CF("set-label", "buildpack", buildpackName, "pci=true", "public-facing=false", "a-third-label=some-value") 122 Eventually(session).Should(Exit(0)) 123 }) 124 AfterEach(func() { 125 deleteResourceByGUID(buildpackGUID, "buildpacks") 126 }) 127 128 It("unsets the specified labels on the buildpack", func() { 129 session := helpers.CF("unset-label", "buildpack", buildpackName, "public-facing", "pci") 130 Eventually(session).Should(Exit(0)) 131 Expect(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for buildpack %s as %s...`), buildpackName, username)) 132 Expect(session).Should(Say("OK")) 133 134 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/buildpacks/%s", buildpackGUID), false, helpers.MetadataLabels{ 135 "a-third-label": "some-value", 136 }) 137 }) 138 }) 139 140 When("the buildpack is unknown", func() { 141 It("displays an error", func() { 142 session := helpers.CF("unset-label", "buildpack", "non-existent-buildpack", "some-key=some-value") 143 Eventually(session).Should(Exit(1)) 144 Expect(session.Err).Should(Say("Buildpack 'non-existent-buildpack' not found")) 145 Expect(session).Should(Say("FAILED")) 146 }) 147 }) 148 149 When("the buildpack exists for multiple stacks", func() { 150 var buildpackGUIDs [2]string 151 BeforeEach(func() { 152 stacks = []string{helpers.PreferredStack(), helpers.CreateStack()} 153 for i := 0; i < 2; i++ { 154 helpers.BuildpackWithStack(func(buildpackPath string) { 155 createSession := helpers.CF("create-buildpack", buildpackName, buildpackPath, fmt.Sprintf("%d", 98+i)) 156 Eventually(createSession).Should(Exit(0)) 157 }, stacks[i]) 158 buildpackGUIDs[i] = helpers.BuildpackGUIDByNameAndStack(buildpackName, stacks[i]) 159 session := helpers.CF("set-label", "buildpack", 160 buildpackName, "-s", stacks[i], 161 "pci=true", 162 fmt.Sprintf("public-facing%d=false", i)) 163 Eventually(session).Should(Exit(0)) 164 } 165 }) 166 AfterEach(func() { 167 for i := 0; i < 2; i++ { 168 deleteResourceByGUID(buildpackGUIDs[i], "buildpacks") 169 } 170 helpers.DeleteStack(stacks[1]) 171 }) 172 173 When("stack is not specified", func() { 174 It("displays an error", func() { 175 session := helpers.CF("unset-label", "buildpack", buildpackName, "pci") 176 Eventually(session).Should(Exit(1)) 177 Expect(session.Err).Should(Say(fmt.Sprintf("Multiple buildpacks named %s found. Specify a stack name by using a '-s' flag.", buildpackName))) 178 Expect(session).Should(Say("FAILED")) 179 }) 180 }) 181 182 When("stack is specified", func() { 183 When("the label is invalid", func() { 184 It("gives an error message", func() { 185 const badLabel = "^^snorky" 186 session := helpers.CF("unset-label", "buildpack", buildpackName, badLabel, "--stack", stacks[0]) 187 Eventually(session).Should(Exit(1)) 188 Expect(session).Should(Say(regexp.QuoteMeta(fmt.Sprintf("Removing label(s) for buildpack %s with stack %s as %s...", buildpackName, stacks[0], username)))) 189 Expect(session.Err).Should(Say(regexp.QuoteMeta(fmt.Sprintf("Metadata label key error: '%s' contains invalid characters", badLabel)))) 190 Expect(session).Should(Say("FAILED")) 191 }) 192 }) 193 194 It("deletes the specified labels from the correct buildpack", func() { 195 session := helpers.CF("unset-label", "buildpack", buildpackName, "pci", "--stack", stacks[0]) 196 Eventually(session).Should(Exit(0)) 197 Expect(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for buildpack %s with stack %s as %s...`), buildpackName, stacks[0], username)) 198 Expect(session).Should(Say("OK")) 199 200 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/buildpacks/%s", buildpackGUIDs[0]), false, helpers.MetadataLabels{ 201 "public-facing0": "false", 202 }) 203 204 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/buildpacks/%s", buildpackGUIDs[1]), false, helpers.MetadataLabels{ 205 "public-facing1": "false", 206 "pci": "true", 207 }) 208 }) 209 }) 210 }) 211 }) 212 213 When("unsetting labels from a domain", func() { 214 215 var ( 216 domainName string 217 domain helpers.Domain 218 ) 219 220 BeforeEach(func() { 221 domainName = helpers.NewDomainName("labels") 222 domain = helpers.NewDomain(orgName, domainName) 223 224 helpers.SetupCFWithOrgOnly(orgName) 225 domain.CreatePrivate() 226 227 session := helpers.CF("set-label", "domain", domainName, 228 "some-key=some-value", "some-other-key=some-other-value", "some-third-key=other") 229 Eventually(session).Should(Exit(0)) 230 }) 231 232 AfterEach(func() { 233 domain.DeletePrivate() 234 helpers.QuickDeleteOrg(orgName) 235 }) 236 237 It("unsets the specified labels on the domain", func() { 238 session := helpers.CF("unset-label", "domain", domainName, "some-other-key", "some-third-key") 239 Eventually(session).Should(Exit(0)) 240 Expect(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for domain %s as %s...`), domainName, username)) 241 Expect(session).Should(Say("OK")) 242 243 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/domains?names=%s", domainName), true, helpers.MetadataLabels{ 244 "some-key": "some-value", 245 }) 246 }) 247 }) 248 249 When("unsetting labels from an org", func() { 250 BeforeEach(func() { 251 helpers.SetupCFWithOrgOnly(orgName) 252 session := helpers.CF("set-label", "org", orgName, "pci=true", "public-facing=false") 253 Eventually(session).Should(Exit(0)) 254 }) 255 AfterEach(func() { 256 helpers.QuickDeleteOrg(orgName) 257 }) 258 259 It("unsets the specified labels on the org", func() { 260 session := helpers.CF("unset-label", "org", orgName, "public-facing") 261 Eventually(session).Should(Exit(0)) 262 Expect(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for org %s as %s...`), orgName, username)) 263 Expect(session).Should(Say("OK")) 264 265 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/organizations/%s", helpers.GetOrgGUID(orgName)), false, helpers.MetadataLabels{ 266 "pci": "true", 267 }) 268 }) 269 }) 270 271 When("unsetting labels from a route", func() { 272 var ( 273 orgGUID string 274 routeName string 275 domainName string 276 domain helpers.Domain 277 ) 278 BeforeEach(func() { 279 orgName = helpers.NewOrgName() 280 spaceName = helpers.NewSpaceName() 281 helpers.SetupCF(orgName, spaceName) 282 283 orgGUID = helpers.GetOrgGUID(orgName) 284 domainName = helpers.NewDomainName() 285 domain = helpers.NewDomain(orgName, domainName) 286 domain.Create() 287 Eventually(helpers.CF("create-route", domainName)).Should(Exit(0)) 288 routeName = domainName 289 290 session := helpers.CF("set-label", "route", routeName, "some-key=some-value", "some-other-key=some-other-value") 291 Eventually(session).Should(Exit(0)) 292 Expect(session).Should(Say(regexp.QuoteMeta(`Setting label(s) for route %s in org %s / space %s as %s...`), routeName, orgName, spaceName, username)) 293 Expect(session).Should(Say("OK")) 294 }) 295 296 AfterEach(func() { 297 Eventually(helpers.CF("delete-route", domainName, "-f")).Should(Exit(0)) 298 domain.Delete() 299 helpers.QuickDeleteOrg(orgName) 300 }) 301 302 It("unsets the specified labels on the route", func() { 303 session := helpers.CF("unset-label", "route", routeName, "some-key") 304 Eventually(session).Should(Exit(0)) 305 Expect(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for route %s in org %s / space %s as %s...`), routeName, orgName, spaceName, username)) 306 Expect(session).Should(Say("OK")) 307 308 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/routes?organization_guids=%s", orgGUID), true, helpers.MetadataLabels{ 309 "some-other-key": "some-other-value", 310 }) 311 }) 312 }) 313 314 When("unsetting labels from a space", func() { 315 BeforeEach(func() { 316 spaceName = helpers.NewSpaceName() 317 helpers.SetupCF(orgName, spaceName) 318 session := helpers.CF("set-label", "space", spaceName, "pci=true", "public-facing=false") 319 Eventually(session).Should(Exit(0)) 320 }) 321 AfterEach(func() { 322 helpers.QuickDeleteOrg(orgName) 323 }) 324 325 It("unsets the specified labels on the space", func() { 326 session := helpers.CF("unset-label", "space", spaceName, "public-facing") 327 Eventually(session).Should(Exit(0)) 328 Expect(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for space %s in org %s as %s...`), spaceName, orgName, username)) 329 Expect(session).Should(Say("OK")) 330 331 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/spaces/%s", helpers.GetSpaceGUID(spaceName)), false, helpers.MetadataLabels{ 332 "pci": "true", 333 }) 334 }) 335 }) 336 337 When("unsetting labels from a stack", func() { 338 var ( 339 stackGUID string 340 stackName string 341 ) 342 343 BeforeEach(func() { 344 helpers.LoginCF() 345 stackName, stackGUID = helpers.CreateStackWithGUID() 346 session := helpers.CF("set-label", "stack", stackName, "pci=true", "public-facing=false") 347 Eventually(session).Should(Exit(0)) 348 }) 349 350 AfterEach(func() { 351 deleteResourceByGUID(stackGUID, "stacks") 352 }) 353 354 It("unsets the specified labels on the stack", func() { 355 session := helpers.CF("unset-label", "stack", stackName, "public-facing") 356 Eventually(session).Should(Exit(0)) 357 Expect(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for stack %s as %s...`), stackName, username)) 358 Expect(session).Should(Say("OK")) 359 360 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/stacks/%s", stackGUID), false, helpers.MetadataLabels{ 361 "pci": "true", 362 }) 363 }) 364 }) 365 366 When("unsetting labels from a service-broker", func() { 367 var broker *servicebrokerstub.ServiceBrokerStub 368 369 BeforeEach(func() { 370 spaceName = helpers.NewSpaceName() 371 helpers.SetupCF(orgName, spaceName) 372 broker = servicebrokerstub.Register() 373 374 session := helpers.CF("set-label", "service-broker", broker.Name, "pci=true", "public-facing=false") 375 Eventually(session).Should(Exit(0)) 376 }) 377 378 AfterEach(func() { 379 helpers.QuickDeleteOrg(orgName) 380 broker.Forget() 381 }) 382 383 It("unsets the specified labels on the service-broker", func() { 384 session := helpers.CF("unset-label", "service-broker", broker.Name, "public-facing") 385 Eventually(session).Should(Exit(0)) 386 Expect(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for service-broker %s as %s...`), broker.Name, username)) 387 Expect(session).Should(Say("OK")) 388 389 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/service_brokers?names=%s", broker.Name), true, helpers.MetadataLabels{ 390 "pci": "true", 391 }) 392 }) 393 }) 394 395 When("unsetting labels from a service-instance", func() { 396 var serviceInstanceName string 397 398 BeforeEach(func() { 399 spaceName = helpers.NewSpaceName() 400 serviceInstanceName = helpers.NewServiceInstanceName() 401 402 helpers.SetupCF(orgName, spaceName) 403 Eventually(helpers.CF("cups", serviceInstanceName)).Should(Exit(0)) 404 405 session := helpers.CF("set-label", "service-instance", serviceInstanceName, "some-key=some-value", "some-other-key=some-other-value", "some-third-key=other") 406 Eventually(session).Should(Exit(0)) 407 }) 408 409 AfterEach(func() { 410 helpers.QuickDeleteOrg(orgName) 411 }) 412 413 It("unsets the specified labels on the service-instance", func() { 414 session := helpers.CF("unset-label", "service-instance", serviceInstanceName, "some-other-key", "some-third-key") 415 Eventually(session).Should(Exit(0)) 416 Expect(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for service-instance %s in org %s / space %s as %s...`), serviceInstanceName, orgName, spaceName, username)) 417 Expect(session).Should(Say("OK")) 418 419 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/service_instances/%s", helpers.ServiceInstanceGUID(serviceInstanceName)), false, helpers.MetadataLabels{ 420 "some-key": "some-value", 421 }) 422 }) 423 }) 424 425 When("unsetting labels from a service-offering", func() { 426 var ( 427 broker *servicebrokerstub.ServiceBrokerStub 428 serviceOfferingName string 429 ) 430 431 BeforeEach(func() { 432 spaceName = helpers.NewSpaceName() 433 helpers.SetupCF(orgName, spaceName) 434 broker = servicebrokerstub.Register() 435 serviceOfferingName = broker.Services[0].Name 436 437 session := helpers.CF("set-label", "service-offering", serviceOfferingName, "pci=true", "public-facing=false") 438 Eventually(session).Should(Exit(0)) 439 }) 440 441 AfterEach(func() { 442 helpers.QuickDeleteOrg(orgName) 443 broker.Forget() 444 }) 445 446 It("unsets the specified labels", func() { 447 session := helpers.CF("unset-label", "service-offering", serviceOfferingName, "public-facing") 448 Eventually(session).Should(Exit(0)) 449 Expect(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for service-offering %s as %s...`), serviceOfferingName, username)) 450 Expect(session).Should(Say("OK")) 451 452 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/service_offerings?names=%s", serviceOfferingName), true, helpers.MetadataLabels{ 453 "pci": "true", 454 }) 455 }) 456 457 When("the service broker name is specified", func() { 458 It("unsets the specified labels", func() { 459 session := helpers.CF("unset-label", "-b", broker.Name, "service-offering", serviceOfferingName, "public-facing") 460 Eventually(session).Should(Exit(0)) 461 Expect(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for service-offering %s from service broker %s as %s...`), serviceOfferingName, broker.Name, username)) 462 Expect(session).Should(Say("OK")) 463 464 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/service_offerings?names=%s", serviceOfferingName), true, helpers.MetadataLabels{ 465 "pci": "true", 466 }) 467 }) 468 }) 469 }) 470 471 When("unsetting labels from a service-plan", func() { 472 var ( 473 broker *servicebrokerstub.ServiceBrokerStub 474 servicePlanName string 475 serviceOfferingName string 476 ) 477 478 BeforeEach(func() { 479 spaceName = helpers.NewSpaceName() 480 helpers.SetupCF(orgName, spaceName) 481 broker = servicebrokerstub.Register() 482 servicePlanName = broker.Services[0].Plans[0].Name 483 serviceOfferingName = broker.Services[0].Name 484 485 session := helpers.CF("set-label", "service-plan", servicePlanName, "pci=true", "public-facing=false") 486 Eventually(session).Should(Exit(0)) 487 }) 488 489 AfterEach(func() { 490 helpers.QuickDeleteOrg(orgName) 491 broker.Forget() 492 }) 493 494 It("unsets the specified labels", func() { 495 session := helpers.CF("unset-label", "service-plan", servicePlanName, "-b", broker.Name, "-e", serviceOfferingName, "public-facing") 496 Eventually(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for service-plan %s from service offering %s / service broker %s as %s...`), servicePlanName, serviceOfferingName, broker.Name, username)) 497 Eventually(session).Should(Exit(0)) 498 Expect(session).Should(Say("OK")) 499 500 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/service_plans?names=%s", servicePlanName), true, helpers.MetadataLabels{ 501 "pci": "true", 502 }) 503 }) 504 }) 505 }) 506 })