github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/v7/isolated/unset_label_command_test.go (about) 1 package isolated 2 3 import ( 4 "fmt" 5 "regexp" 6 7 . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" 8 "code.cloudfoundry.org/cli/integration/helpers/fakeservicebroker" 9 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("unset-label 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("unset-label", "METADATA", "Unset a label (key-value pairs) for an API resource")) 23 }) 24 25 It("Displays command usage to output", func() { 26 session := helpers.CF("unset-label", "--help") 27 28 Eventually(session).Should(Say("NAME:")) 29 Eventually(session).Should(Say(`\s+unset-label - Unset a label \(key-value pairs\) for an API resource`)) 30 Eventually(session).Should(Say("USAGE:")) 31 Eventually(session).Should(Say(`\s+cf unset-label RESOURCE RESOURCE_NAME KEY...`)) 32 Eventually(session).Should(Say("EXAMPLES:")) 33 Eventually(session).Should(Say(`\s+cf unset-label app dora ci_signature_sha2`)) 34 Eventually(session).Should(Say(`\s+cf unset-label org business pci public-facing`)) 35 Eventually(session).Should(Say(`\s+cf unset-label buildpack go_buildpack go -s 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+space`)) 44 Eventually(session).Should(Say(`\s+stack`)) 45 Eventually(session).Should(Say("OPTIONS:")) 46 Eventually(session).Should(Say(`\s+--stack, -s\s+Specify stack to disambiguate buildpacks with the same name`)) 47 Eventually(session).Should(Say("SEE ALSO:")) 48 Eventually(session).Should(Say(`\s+labels, set-label`)) 49 Eventually(session).Should(Exit(0)) 50 }) 51 }) 52 53 When("the environment is set up correctly", func() { 54 var ( 55 orgName string 56 spaceName string 57 username string 58 ) 59 60 BeforeEach(func() { 61 username, _ = helpers.GetCredentials() 62 helpers.LoginCF() 63 orgName = helpers.NewOrgName() 64 }) 65 66 When("unsetting labels from an app", func() { 67 var appName string 68 69 BeforeEach(func() { 70 spaceName = helpers.NewSpaceName() 71 appName = helpers.PrefixedRandomName("app") 72 73 helpers.SetupCF(orgName, spaceName) 74 helpers.WithHelloWorldApp(func(appDir string) { 75 Eventually(helpers.CF("push", appName, "-p", appDir, "--no-start")).Should(Exit(0)) 76 }) 77 78 session := helpers.CF("set-label", "app", appName, "some-key=some-value", "some-other-key=some-other-value", "some-third-key=other") 79 Eventually(session).Should(Exit(0)) 80 }) 81 AfterEach(func() { 82 helpers.QuickDeleteOrg(orgName) 83 }) 84 85 It("unsets the specified labels on the app", func() { 86 session := helpers.CF("unset-label", "app", appName, "some-other-key", "some-third-key") 87 Eventually(session).Should(Exit(0)) 88 Expect(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for app %s in org %s / space %s as %s...`), appName, orgName, spaceName, username)) 89 Expect(session).Should(Say("OK")) 90 91 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/apps/%s", helpers.AppGUID(appName)), false, helpers.MetadataLabels{ 92 "some-key": "some-value", 93 }) 94 }) 95 }) 96 97 When("unsetting labels from a buildpack", func() { 98 var ( 99 buildpackName string 100 buildpackGUID string 101 stacks []string 102 ) 103 BeforeEach(func() { 104 helpers.LoginCF() 105 buildpackName = helpers.NewBuildpackName() 106 }) 107 108 When("there is only one instance of the given buildpack", func() { 109 110 BeforeEach(func() { 111 stacks = helpers.FetchStacks() 112 helpers.BuildpackWithStack(func(buildpackPath string) { 113 session := helpers.CF("create-buildpack", buildpackName, buildpackPath, "98") 114 Eventually(session).Should(Exit(0)) 115 }, stacks[0]) 116 buildpackGUID = helpers.BuildpackGUIDByNameAndStack(buildpackName, stacks[0]) 117 session := helpers.CF("set-label", "buildpack", buildpackName, "pci=true", "public-facing=false", "a-third-label=some-value") 118 Eventually(session).Should(Exit(0)) 119 }) 120 AfterEach(func() { 121 deleteResourceByGUID(buildpackGUID, "buildpacks") 122 }) 123 124 It("unsets the specified labels on the buildpack", func() { 125 session := helpers.CF("unset-label", "buildpack", buildpackName, "public-facing", "pci") 126 Eventually(session).Should(Exit(0)) 127 Expect(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for buildpack %s as %s...`), buildpackName, username)) 128 Expect(session).Should(Say("OK")) 129 130 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/buildpacks/%s", buildpackGUID), false, helpers.MetadataLabels{ 131 "a-third-label": "some-value", 132 }) 133 }) 134 }) 135 136 When("the buildpack is unknown", func() { 137 It("displays an error", func() { 138 session := helpers.CF("unset-label", "buildpack", "non-existent-buildpack", "some-key=some-value") 139 Eventually(session).Should(Exit(1)) 140 Expect(session.Err).Should(Say("Buildpack 'non-existent-buildpack' not found")) 141 Expect(session).Should(Say("FAILED")) 142 }) 143 }) 144 145 When("the buildpack exists for multiple stacks", func() { 146 var buildpackGUIDs [2]string 147 BeforeEach(func() { 148 stacks = []string{helpers.PreferredStack(), helpers.CreateStack()} 149 for i := 0; i < 2; i++ { 150 helpers.BuildpackWithStack(func(buildpackPath string) { 151 createSession := helpers.CF("create-buildpack", buildpackName, buildpackPath, fmt.Sprintf("%d", 98+i)) 152 Eventually(createSession).Should(Exit(0)) 153 }, stacks[i]) 154 buildpackGUIDs[i] = helpers.BuildpackGUIDByNameAndStack(buildpackName, stacks[i]) 155 session := helpers.CF("set-label", "buildpack", 156 buildpackName, "-s", stacks[i], 157 "pci=true", 158 fmt.Sprintf("public-facing%d=false", i)) 159 Eventually(session).Should(Exit(0)) 160 } 161 }) 162 AfterEach(func() { 163 for i := 0; i < 2; i++ { 164 deleteResourceByGUID(buildpackGUIDs[i], "buildpacks") 165 } 166 helpers.DeleteStack(stacks[1]) 167 }) 168 169 When("stack is not specified", func() { 170 It("displays an error", func() { 171 session := helpers.CF("unset-label", "buildpack", buildpackName, "pci") 172 Eventually(session).Should(Exit(1)) 173 Expect(session.Err).Should(Say(fmt.Sprintf("Multiple buildpacks named %s found. Specify a stack name by using a '-s' flag.", buildpackName))) 174 Expect(session).Should(Say("FAILED")) 175 }) 176 }) 177 178 When("stack is specified", func() { 179 When("the label is invalid", func() { 180 It("gives an error message", func() { 181 const badLabel = "^^snorky" 182 session := helpers.CF("unset-label", "buildpack", buildpackName, badLabel, "--stack", stacks[0]) 183 Eventually(session).Should(Exit(1)) 184 Expect(session).Should(Say(regexp.QuoteMeta(fmt.Sprintf("Removing label(s) for buildpack %s with stack %s as %s...", buildpackName, stacks[0], username)))) 185 Expect(session.Err).Should(Say(regexp.QuoteMeta(fmt.Sprintf("Metadata label key error: '%s' contains invalid characters", badLabel)))) 186 Expect(session).Should(Say("FAILED")) 187 }) 188 }) 189 190 It("deletes the specified labels from the correct buildpack", func() { 191 session := helpers.CF("unset-label", "buildpack", buildpackName, "pci", "--stack", stacks[0]) 192 Eventually(session).Should(Exit(0)) 193 Expect(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for buildpack %s with stack %s as %s...`), buildpackName, stacks[0], username)) 194 Expect(session).Should(Say("OK")) 195 196 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/buildpacks/%s", buildpackGUIDs[0]), false, helpers.MetadataLabels{ 197 "public-facing0": "false", 198 }) 199 200 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/buildpacks/%s", buildpackGUIDs[1]), false, helpers.MetadataLabels{ 201 "public-facing1": "false", 202 "pci": "true", 203 }) 204 }) 205 }) 206 }) 207 }) 208 209 When("unsetting labels from a domain", func() { 210 211 var ( 212 domainName string 213 domain helpers.Domain 214 ) 215 216 BeforeEach(func() { 217 domainName = helpers.NewDomainName("labels") 218 domain = helpers.NewDomain(orgName, domainName) 219 220 helpers.SetupCFWithOrgOnly(orgName) 221 domain.CreatePrivate() 222 223 session := helpers.CF("set-label", "domain", domainName, 224 "some-key=some-value", "some-other-key=some-other-value", "some-third-key=other") 225 Eventually(session).Should(Exit(0)) 226 }) 227 228 AfterEach(func() { 229 domain.DeletePrivate() 230 helpers.QuickDeleteOrg(orgName) 231 }) 232 233 It("unsets the specified labels on the domain", func() { 234 session := helpers.CF("unset-label", "domain", domainName, "some-other-key", "some-third-key") 235 Eventually(session).Should(Exit(0)) 236 Expect(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for domain %s as %s...`), domainName, username)) 237 Expect(session).Should(Say("OK")) 238 239 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/domains?names=%s", domainName), true, helpers.MetadataLabels{ 240 "some-key": "some-value", 241 }) 242 }) 243 }) 244 245 When("unsetting labels from an org", func() { 246 BeforeEach(func() { 247 helpers.SetupCFWithOrgOnly(orgName) 248 session := helpers.CF("set-label", "org", orgName, "pci=true", "public-facing=false") 249 Eventually(session).Should(Exit(0)) 250 }) 251 AfterEach(func() { 252 helpers.QuickDeleteOrg(orgName) 253 }) 254 255 It("unsets the specified labels on the org", func() { 256 session := helpers.CF("unset-label", "org", orgName, "public-facing") 257 Eventually(session).Should(Exit(0)) 258 Expect(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for org %s as %s...`), orgName, username)) 259 Expect(session).Should(Say("OK")) 260 261 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/organizations/%s", helpers.GetOrgGUID(orgName)), false, helpers.MetadataLabels{ 262 "pci": "true", 263 }) 264 }) 265 }) 266 267 When("unsetting labels from a route", func() { 268 var ( 269 orgGUID string 270 routeName string 271 domainName string 272 domain helpers.Domain 273 ) 274 BeforeEach(func() { 275 orgName = helpers.NewOrgName() 276 spaceName = helpers.NewSpaceName() 277 helpers.SetupCF(orgName, spaceName) 278 279 orgGUID = helpers.GetOrgGUID(orgName) 280 domainName = helpers.NewDomainName() 281 domain = helpers.NewDomain(orgName, domainName) 282 domain.Create() 283 Eventually(helpers.CF("create-route", domainName)).Should(Exit(0)) 284 routeName = domainName 285 286 session := helpers.CF("set-label", "route", routeName, "some-key=some-value", "some-other-key=some-other-value") 287 Eventually(session).Should(Exit(0)) 288 Expect(session).Should(Say(regexp.QuoteMeta(`Setting label(s) for route %s in org %s / space %s as %s...`), routeName, orgName, spaceName, username)) 289 Expect(session).Should(Say("OK")) 290 }) 291 292 AfterEach(func() { 293 Eventually(helpers.CF("delete-route", domainName, "-f")).Should(Exit(0)) 294 domain.Delete() 295 helpers.QuickDeleteOrg(orgName) 296 }) 297 298 It("unsets the specified labels on the route", func() { 299 session := helpers.CF("unset-label", "route", routeName, "some-key") 300 Eventually(session).Should(Exit(0)) 301 Expect(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for route %s in org %s / space %s as %s...`), routeName, orgName, spaceName, username)) 302 Expect(session).Should(Say("OK")) 303 304 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/routes?organization_guids=%s", orgGUID), true, helpers.MetadataLabels{ 305 "some-other-key": "some-other-value", 306 }) 307 }) 308 }) 309 310 When("unsetting labels from a space", func() { 311 BeforeEach(func() { 312 spaceName = helpers.NewSpaceName() 313 helpers.SetupCF(orgName, spaceName) 314 session := helpers.CF("set-label", "space", spaceName, "pci=true", "public-facing=false") 315 Eventually(session).Should(Exit(0)) 316 }) 317 AfterEach(func() { 318 helpers.QuickDeleteOrg(orgName) 319 }) 320 321 It("unsets the specified labels on the space", func() { 322 session := helpers.CF("unset-label", "space", spaceName, "public-facing") 323 Eventually(session).Should(Exit(0)) 324 Expect(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for space %s in org %s as %s...`), spaceName, orgName, username)) 325 Expect(session).Should(Say("OK")) 326 327 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/spaces/%s", helpers.GetSpaceGUID(spaceName)), false, helpers.MetadataLabels{ 328 "pci": "true", 329 }) 330 }) 331 }) 332 333 When("unsetting labels from a stack", func() { 334 var ( 335 stackGUID string 336 stackName string 337 ) 338 339 BeforeEach(func() { 340 helpers.LoginCF() 341 stackName, stackGUID = helpers.CreateStackWithGUID() 342 session := helpers.CF("set-label", "stack", stackName, "pci=true", "public-facing=false") 343 Eventually(session).Should(Exit(0)) 344 }) 345 346 AfterEach(func() { 347 deleteResourceByGUID(stackGUID, "stacks") 348 }) 349 350 It("unsets the specified labels on the stack", func() { 351 session := helpers.CF("unset-label", "stack", stackName, "public-facing") 352 Eventually(session).Should(Exit(0)) 353 Expect(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for stack %s as %s...`), stackName, username)) 354 Expect(session).Should(Say("OK")) 355 356 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/stacks/%s", stackGUID), false, helpers.MetadataLabels{ 357 "pci": "true", 358 }) 359 }) 360 }) 361 362 When("unsetting labels from a service-broker", func() { 363 var broker *fakeservicebroker.FakeServiceBroker 364 365 BeforeEach(func() { 366 spaceName = helpers.NewSpaceName() 367 helpers.SetupCF(orgName, spaceName) 368 broker = fakeservicebroker.New().EnsureBrokerIsAvailable() 369 370 session := helpers.CF("set-label", "service-broker", broker.Name(), "pci=true", "public-facing=false") 371 Eventually(session).Should(Exit(0)) 372 }) 373 374 AfterEach(func() { 375 broker.Destroy() 376 helpers.QuickDeleteOrg(orgName) 377 }) 378 379 It("unsets the specified labels on the service-broker", func() { 380 session := helpers.CF("unset-label", "service-broker", broker.Name(), "public-facing") 381 Eventually(session).Should(Exit(0)) 382 Expect(session).Should(Say(regexp.QuoteMeta(`Removing label(s) for service-broker %s as %s...`), broker.Name(), username)) 383 Expect(session).Should(Say("OK")) 384 385 helpers.CheckExpectedLabels(fmt.Sprintf("/v3/service_brokers?names=%s", broker.Name()), true, helpers.MetadataLabels{ 386 "pci": "true", 387 }) 388 }) 389 }) 390 }) 391 })