github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+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/cf/util/testhelpers/matchers"
     8  
     9  	"code.cloudfoundry.org/cli/integration/helpers"
    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("labels 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("labels", "METADATA", "List all labels (key-value pairs) for an API resource"))
    22  		})
    23  
    24  		It("Displays command usage", func() {
    25  			session := helpers.CF("labels", "--help")
    26  
    27  			Eventually(session).Should(Say("NAME:"))
    28  			Eventually(session).Should(Say(`\s+labels - List all labels \(key-value pairs\) for an API resource`))
    29  			Eventually(session).Should(Say("USAGE:"))
    30  			Eventually(session).Should(Say(`\s+cf labels RESOURCE RESOURCE_NAME`))
    31  			Eventually(session).Should(Say("EXAMPLES:"))
    32  			Eventually(session).Should(Say(`\s+cf labels app dora`))
    33  			Eventually(session).Should(Say(`\s+cf labels org business`))
    34  			Eventually(session).Should(Say(`\s+cf labels buildpack go_buildpack --stack 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+space`))
    42  			Eventually(session).Should(Say(`\s+stack`))
    43  			Eventually(session).Should(Say("OPTIONS:"))
    44  			Eventually(session).Should(Say(`\s+--stack, -s\s+Specify stack to disambiguate buildpacks with the same name`))
    45  			Eventually(session).Should(Say("SEE ALSO:"))
    46  			Eventually(session).Should(Say(`\s+set-label, unset-label`))
    47  			Eventually(session).Should(Exit(0))
    48  		})
    49  	})
    50  
    51  	When("the environment is set up correctly", func() {
    52  		var (
    53  			appName       string
    54  			buildpackName string
    55  			orgName       string
    56  			spaceName     string
    57  			stackName     string
    58  			username      string
    59  		)
    60  
    61  		BeforeEach(func() {
    62  			orgName = helpers.NewOrgName()
    63  			buildpackName = helpers.NewBuildpackName()
    64  			stackName = helpers.NewStackName()
    65  			username, _ = helpers.GetCredentials()
    66  		})
    67  
    68  		Describe("app labels", func() {
    69  			BeforeEach(func() {
    70  				spaceName = helpers.NewSpaceName()
    71  				appName = helpers.PrefixedRandomName("app")
    72  				helpers.SetupCF(orgName, spaceName)
    73  				helpers.WithHelloWorldApp(func(appDir string) {
    74  					Eventually(helpers.CF("push", appName, "-p", appDir, "--no-start")).Should(Exit(0))
    75  				})
    76  			})
    77  			AfterEach(func() {
    78  				helpers.QuickDeleteOrg(orgName)
    79  			})
    80  
    81  			When("there are labels set on the application", func() {
    82  				BeforeEach(func() {
    83  					session := helpers.CF("set-label", "app", appName, "some-other-key=some-other-value", "some-key=some-value")
    84  					Eventually(session).Should(Exit(0))
    85  				})
    86  
    87  				It("lists the labels", func() {
    88  					session := helpers.CF("labels", "app", appName)
    89  					Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for app %s in org %s / space %s as %s...\n\n"), appName, orgName, spaceName, username))
    90  					Eventually(session).Should(Say(`key\s+value`))
    91  					Eventually(session).Should(Say(`some-key\s+some-value`))
    92  					Eventually(session).Should(Say(`some-other-key\s+some-other-value`))
    93  					Eventually(session).Should(Exit(0))
    94  				})
    95  			})
    96  
    97  			When("there are no labels set on the application", func() {
    98  				It("indicates that there are no labels", func() {
    99  					session := helpers.CF("labels", "app", appName)
   100  					Eventually(session).Should(Exit(0))
   101  					Expect(session).Should(Say(regexp.QuoteMeta("Getting labels for app %s in org %s / space %s as %s...\n\n"), appName, orgName, spaceName, username))
   102  					Expect(session).ToNot(Say(`key\s+value`))
   103  					Expect(session).Should(Say("No labels found."))
   104  				})
   105  			})
   106  
   107  			When("the app does not exist", func() {
   108  				It("displays an error", func() {
   109  					session := helpers.CF("labels", "app", "non-existent-app")
   110  					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))
   111  					Eventually(session.Err).Should(Say("App 'non-existent-app' not found"))
   112  					Eventually(session).Should(Say("FAILED"))
   113  					Eventually(session).Should(Exit(1))
   114  				})
   115  			})
   116  		})
   117  
   118  		Describe("buildpack labels", func() {
   119  			BeforeEach(func() {
   120  				helpers.LoginCF()
   121  			})
   122  
   123  			When("there is exactly one buildpack with a given name", func() {
   124  				When("the buildpack is not bound to a stack", func() {
   125  					BeforeEach(func() {
   126  						helpers.SetupBuildpackWithoutStack(buildpackName)
   127  					})
   128  					AfterEach(func() {
   129  						session := helpers.CF("delete-buildpack", buildpackName, "-f")
   130  						Eventually(session).Should(Exit(0))
   131  					})
   132  
   133  					It("fails if a non-existent stack is specified", func() {
   134  						session := helpers.CF("labels", "buildpack", buildpackName, "-s", "bogus-stack")
   135  						Eventually(session.Err).Should(Say("Buildpack '%s' with stack 'bogus-stack' not found", buildpackName))
   136  						Eventually(session).Should(Say("FAILED"))
   137  						Eventually(session).Should(Exit(1))
   138  					})
   139  
   140  					It("fails if the -s is specified without an argument", func() {
   141  						session := helpers.CF("labels", "buildpack", buildpackName, "-s")
   142  						Eventually(session.Err).Should(Say("Incorrect Usage:"))
   143  						Eventually(session).Should(Exit(1))
   144  					})
   145  
   146  					It("indicates that there are no labels", func() {
   147  						session := helpers.CF("labels", "buildpack", buildpackName)
   148  						Eventually(session).Should(Exit(0))
   149  						Expect(session).Should(Say(regexp.QuoteMeta("Getting labels for buildpack %s as %s...\n\n"), buildpackName, username))
   150  						Expect(session).ToNot(Say(`key\s+value`))
   151  						Expect(session).Should(Say("No labels found."))
   152  					})
   153  
   154  					When("there are labels on the buildpack", func() {
   155  						BeforeEach(func() {
   156  							session := helpers.CF("set-label", "buildpack", buildpackName, "some-other-key=some-other-value", "some-key=some-value")
   157  							Eventually(session).Should(Exit(0))
   158  						})
   159  
   160  						It("lists the labels when no -s flag is given", func() {
   161  							session := helpers.CF("labels", "buildpack", buildpackName)
   162  							Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for buildpack %s as %s...\n\n"), buildpackName, username))
   163  							Eventually(session).Should(Say(`key\s+value`))
   164  							Eventually(session).Should(Say(`some-key\s+some-value`))
   165  							Eventually(session).Should(Say(`some-other-key\s+some-other-value`))
   166  							Eventually(session).Should(Exit(0))
   167  						})
   168  
   169  						It("lists the labels when the -s flag is given with an empty-string", func() {
   170  							session := helpers.CF("labels", "buildpack", buildpackName, "-s", "")
   171  							Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for buildpack %s as %s...\n\n"), buildpackName, username))
   172  							Eventually(session).Should(Say(`key\s+value`))
   173  							Eventually(session).Should(Say(`some-key\s+some-value`))
   174  							Eventually(session).Should(Say(`some-other-key\s+some-other-value`))
   175  							Eventually(session).Should(Exit(0))
   176  						})
   177  					})
   178  				})
   179  
   180  				When("the buildpack is bound to a stack", func() {
   181  					BeforeEach(func() {
   182  						helpers.SetupBuildpackWithStack(buildpackName, "cflinuxfs3")
   183  						session := helpers.CF("set-label", "buildpack", buildpackName, "-s", "cflinuxfs3", "some-other-key=some-other-value", "some-key=some-value")
   184  						Eventually(session).Should(Exit(0))
   185  					})
   186  					AfterEach(func() {
   187  						session := helpers.CF("delete-buildpack", buildpackName, "-f", "-s", "cflinuxfs3")
   188  						Eventually(session).Should(Exit(0))
   189  					})
   190  
   191  					It("lists the labels when no stack is specified", func() {
   192  						session := helpers.CF("labels", "buildpack", buildpackName)
   193  						Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for buildpack %s as %s...\n\n"), buildpackName, username))
   194  						Eventually(session).Should(Say(`key\s+value`))
   195  						Eventually(session).Should(Say(`some-key\s+some-value`))
   196  						Eventually(session).Should(Say(`some-other-key\s+some-other-value`))
   197  						Eventually(session).Should(Exit(0))
   198  					})
   199  
   200  					It("lists the labels when the stack is specified", func() {
   201  						session := helpers.CF("labels", "buildpack", buildpackName, "-s", "cflinuxfs3")
   202  						Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for buildpack %s with stack %s as %s...\n\n"), buildpackName, "cflinuxfs3", username))
   203  						Eventually(session).Should(Say(`key\s+value`))
   204  						Eventually(session).Should(Say(`some-key\s+some-value`))
   205  						Eventually(session).Should(Say(`some-other-key\s+some-other-value`))
   206  						Eventually(session).Should(Exit(0))
   207  					})
   208  
   209  					It("fails if a non-existent stack is specified", func() {
   210  						session := helpers.CF("labels", "buildpack", buildpackName, "-s", "bogus-stack")
   211  						Eventually(session.Err).Should(Say("Buildpack '%s' with stack 'bogus-stack' not found", buildpackName))
   212  						Eventually(session).Should(Say("FAILED"))
   213  						Eventually(session).Should(Exit(1))
   214  					})
   215  				})
   216  			})
   217  
   218  			When("there are multiple buildpacks with the same name", func() {
   219  				var (
   220  					newStackName string
   221  				)
   222  
   223  				BeforeEach(func() {
   224  					newStackName = helpers.NewStackName()
   225  					helpers.CreateStack(newStackName)
   226  					helpers.SetupBuildpackWithStack(buildpackName, newStackName)
   227  					helpers.SetupBuildpackWithStack(buildpackName, "cflinuxfs3")
   228  					session := helpers.CF("set-label", "buildpack", buildpackName, "-s", newStackName,
   229  						"my-stack-some-other-key=some-other-value", "some-key=some-value")
   230  					Eventually(session).Should(Exit(0))
   231  					session = helpers.CF("set-label", "buildpack", buildpackName, "--stack", "cflinuxfs3",
   232  						"cfl2=var2", "cfl1=var1")
   233  					Eventually(session).Should(Exit(0))
   234  				})
   235  				AfterEach(func() {
   236  					session := helpers.CF("delete-buildpack", buildpackName, "-f", "-s", "cflinuxfs3")
   237  					Eventually(session).Should(Exit(0))
   238  					session = helpers.CF("delete-buildpack", buildpackName, "-f", "-s", newStackName)
   239  					Eventually(session).Should(Exit(0))
   240  					helpers.DeleteStack(newStackName)
   241  				})
   242  
   243  				It("fails when no stack is given", func() {
   244  					session := helpers.CF("labels", "buildpack", buildpackName)
   245  					Eventually(session.Err).Should(Say(fmt.Sprintf(`Multiple buildpacks named %s found. Specify a stack name by using a '-s' flag.`, buildpackName)))
   246  					Eventually(session).Should(Say(`FAILED`))
   247  					Eventually(session).Should(Exit(1))
   248  				})
   249  
   250  				It("fails when an empty-string stack is given", func() {
   251  					session := helpers.CF("labels", "buildpack", buildpackName, "--stack", "")
   252  					Eventually(session.Err).Should(Say(fmt.Sprintf(`Multiple buildpacks named %s found. Specify a stack name by using a '-s' flag.`, buildpackName)))
   253  					Eventually(session).Should(Say(`FAILED`))
   254  					Eventually(session).Should(Exit(1))
   255  				})
   256  
   257  				It("fails when a non-existent stack is given", func() {
   258  					session := helpers.CF("labels", "buildpack", buildpackName, "-s", "bogus-stack")
   259  					Eventually(session.Err).Should(Say("Buildpack '%s' with stack 'bogus-stack' not found", buildpackName))
   260  					Eventually(session).Should(Say("FAILED"))
   261  					Eventually(session).Should(Exit(1))
   262  				})
   263  
   264  				It("lists the labels for buildpackName/newStackName", func() {
   265  					session := helpers.CF("labels", "buildpack", buildpackName, "-s", newStackName)
   266  					Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for buildpack %s with stack %s as %s...\n\n"), buildpackName, newStackName, username))
   267  					Eventually(session).Should(Say(`key\s+value`))
   268  					Eventually(session).Should(Say(`my-stack-some-other-key\s+some-other-value`))
   269  					Eventually(session).Should(Say(`some-key\s+some-value`))
   270  					Eventually(session).Should(Exit(0))
   271  				})
   272  
   273  				It("lists the labels for buildpackName/cflinuxfs3", func() {
   274  					session := helpers.CF("labels", "buildpack", buildpackName, "--stack", "cflinuxfs3")
   275  					Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for buildpack %s with stack cflinuxfs3 as %s...\n\n"), buildpackName, username))
   276  					Eventually(session).Should(Say(`key\s+value`))
   277  					Eventually(session).Should(Say(`cfl1\s+var1`))
   278  					Eventually(session).Should(Say(`cfl2\s+var2`))
   279  					Eventually(session).Should(Exit(0))
   280  				})
   281  
   282  				When("there is also a buildpack with the same name but has no stack", func() {
   283  					BeforeEach(func() {
   284  						helpers.SetupBuildpackWithoutStack(buildpackName)
   285  						session := helpers.CF("set-label", "buildpack", buildpackName,
   286  							"nostack1=var1", "nostack2=var2")
   287  						Eventually(session).Should(Exit(0))
   288  
   289  					})
   290  					AfterEach(func() {
   291  						session := helpers.CF("delete-buildpack", buildpackName, "-f")
   292  						Eventually(session).Should(Exit(0))
   293  					})
   294  
   295  					It("lists the labels of the no-stack buildpack when no stack is specified", func() {
   296  						session := helpers.CF("labels", "buildpack", buildpackName)
   297  						Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for buildpack %s as %s...\n\n"), buildpackName, username))
   298  						Eventually(session).Should(Say(`key\s+value`))
   299  						Eventually(session).Should(Say(`nostack1\s+var1`))
   300  						Eventually(session).Should(Say(`nostack2\s+var2`))
   301  						Eventually(session).Should(Exit(0))
   302  					})
   303  
   304  					It("fails if a non-existent stack is specified", func() {
   305  						session := helpers.CF("labels", "buildpack", buildpackName, "-s", "bogus-stack")
   306  						Eventually(session.Err).Should(Say("Buildpack '%s' with stack 'bogus-stack' not found", buildpackName))
   307  						Eventually(session).Should(Say("FAILED"))
   308  						Eventually(session).Should(Exit(1))
   309  					})
   310  				})
   311  			})
   312  		})
   313  
   314  		Describe("domain labels", func() {
   315  			var (
   316  				domainName string
   317  				domain     helpers.Domain
   318  			)
   319  
   320  			BeforeEach(func() {
   321  				domainName = helpers.NewDomainName("labels")
   322  				domain = helpers.NewDomain(orgName, domainName)
   323  
   324  				helpers.SetupCFWithOrgOnly(orgName)
   325  				domain.CreatePrivate()
   326  			})
   327  
   328  			AfterEach(func() {
   329  				domain.DeletePrivate()
   330  				helpers.QuickDeleteOrg(orgName)
   331  			})
   332  
   333  			When("there are labels set on the domain", func() {
   334  				BeforeEach(func() {
   335  					session := helpers.CF("set-label", "domain", domainName, "some-other-key=some-other-value", "some-key=some-value")
   336  					Eventually(session).Should(Exit(0))
   337  				})
   338  
   339  				It("lists the labels", func() {
   340  					session := helpers.CF("labels", "domain", domainName)
   341  					Eventually(session).Should(Exit(0))
   342  					Expect(session).To(Say(regexp.QuoteMeta("Getting labels for domain %s as %s...\n\n"), domainName, username))
   343  					Expect(session).To(Say(`key\s+value`))
   344  					Expect(session).To(Say(`some-key\s+some-value`))
   345  					Expect(session).To(Say(`some-other-key\s+some-other-value`))
   346  				})
   347  			})
   348  
   349  			When("there are no labels set on the domain", func() {
   350  				It("indicates that there are no labels", func() {
   351  					session := helpers.CF("labels", "domain", domainName)
   352  					Eventually(session).Should(Exit(0))
   353  					Expect(session).To(Say(regexp.QuoteMeta("Getting labels for domain %s as %s...\n\n"), domainName, username))
   354  					Expect(session).ToNot(Say(`key\s+value`))
   355  					Expect(session).Should(Say("No labels found."))
   356  				})
   357  			})
   358  
   359  			When("the domain does not exist", func() {
   360  				It("displays an error", func() {
   361  					session := helpers.CF("labels", "domain", "non-existent-domain")
   362  					Eventually(session).Should(Exit(1))
   363  					Expect(session).To(Say(regexp.QuoteMeta("Getting labels for domain non-existent-domain as %s...\n\n"), username))
   364  					Expect(session.Err).To(Say("Domain 'non-existent-domain' not found"))
   365  					Expect(session).To(Say("FAILED"))
   366  				})
   367  			})
   368  		})
   369  
   370  		Describe("org labels", func() {
   371  			BeforeEach(func() {
   372  				helpers.SetupCFWithOrgOnly(orgName)
   373  			})
   374  			AfterEach(func() {
   375  				helpers.QuickDeleteOrg(orgName)
   376  			})
   377  
   378  			When("there are labels set on the organization", func() {
   379  				BeforeEach(func() {
   380  					session := helpers.CF("set-label", "org", orgName, "some-other-key=some-other-value", "some-key=some-value")
   381  					Eventually(session).Should(Exit(0))
   382  				})
   383  				It("lists the labels", func() {
   384  					session := helpers.CF("labels", "org", orgName)
   385  					Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for org %s as %s...\n\n"), orgName, username))
   386  					Eventually(session).Should(Say(`key\s+value`))
   387  					Eventually(session).Should(Say(`some-key\s+some-value`))
   388  					Eventually(session).Should(Say(`some-other-key\s+some-other-value`))
   389  					Eventually(session).Should(Exit(0))
   390  				})
   391  			})
   392  
   393  			When("there are no labels set on the organization", func() {
   394  				It("indicates that there are no labels", func() {
   395  					session := helpers.CF("labels", "org", orgName)
   396  					Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for org %s as %s...\n\n"), orgName, username))
   397  					Expect(session).ToNot(Say(`key\s+value`))
   398  					Eventually(session).Should(Say("No labels found."))
   399  					Eventually(session).Should(Exit(0))
   400  				})
   401  			})
   402  
   403  			When("the org does not exist", func() {
   404  				It("displays an error", func() {
   405  					session := helpers.CF("labels", "org", "non-existent-org")
   406  					Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for org %s as %s...\n\n"), "non-existent-org", username))
   407  					Eventually(session.Err).Should(Say("Organization 'non-existent-org' not found"))
   408  					Eventually(session).Should(Say("FAILED"))
   409  					Eventually(session).Should(Exit(1))
   410  				})
   411  			})
   412  		})
   413  
   414  		Describe("route labels", func() {
   415  			var (
   416  				routeName  string
   417  				domainName string
   418  				domain     helpers.Domain
   419  			)
   420  
   421  			BeforeEach(func() {
   422  				orgName = helpers.NewOrgName()
   423  				spaceName = helpers.NewSpaceName()
   424  				helpers.SetupCF(orgName, spaceName)
   425  
   426  				domainName = helpers.NewDomainName()
   427  				domain = helpers.NewDomain(orgName, domainName)
   428  				domain.Create()
   429  				Eventually(helpers.CF("create-route", domainName)).Should(Exit(0))
   430  				routeName = domainName
   431  			})
   432  
   433  			AfterEach(func() {
   434  				Eventually(helpers.CF("delete-route", domainName, "-f")).Should(Exit(0))
   435  				domain.Delete()
   436  				helpers.QuickDeleteOrg(orgName)
   437  			})
   438  
   439  			When("there are labels set on the route", func() {
   440  				BeforeEach(func() {
   441  					session := helpers.CF("set-label", "route", routeName, "some-other-key=some-other-value", "some-key=some-value")
   442  					Eventually(session).Should(Exit(0))
   443  				})
   444  
   445  				It("lists the labels", func() {
   446  					session := helpers.CF("labels", "route", routeName)
   447  					Eventually(session).Should(Exit(0))
   448  					Expect(session).Should(Say(regexp.QuoteMeta("Getting labels for route %s in org %s / space %s as %s...\n\n"), routeName, orgName, spaceName, username))
   449  					Expect(session).To(Say(`key\s+value`))
   450  					Expect(session).To(Say(`some-key\s+some-value`))
   451  					Expect(session).To(Say(`some-other-key\s+some-other-value`))
   452  				})
   453  			})
   454  
   455  			When("there are no labels set on the route", func() {
   456  				It("indicates that there are no labels", func() {
   457  					session := helpers.CF("labels", "route", routeName)
   458  					Eventually(session).Should(Exit(0))
   459  					Expect(session).Should(Say(regexp.QuoteMeta("Getting labels for route %s in org %s / space %s as %s...\n\n"), routeName, orgName, spaceName, username))
   460  					Expect(session).ToNot(Say(`key\s+value`))
   461  					Expect(session).Should(Say("No labels found."))
   462  				})
   463  			})
   464  
   465  			When("the route does not exist", func() {
   466  				It("displays an error", func() {
   467  					session := helpers.CF("labels", "route", "non-existent-route.example.com")
   468  					Eventually(session).Should(Exit(1))
   469  					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))
   470  					Expect(session.Err).To(Say("Domain 'example.com' not found"))
   471  					Expect(session).To(Say("FAILED"))
   472  				})
   473  			})
   474  		})
   475  
   476  		Describe("stack labels", func() {
   477  			BeforeEach(func() {
   478  				helpers.LoginCF()
   479  				helpers.CreateStack(stackName)
   480  			})
   481  			AfterEach(func() {
   482  				helpers.DeleteStack(stackName)
   483  			})
   484  
   485  			When("there are labels set on the stack", func() {
   486  				BeforeEach(func() {
   487  					session := helpers.CF("set-label", "stack", stackName, "some-other-key=some-other-value", "some-key=some-value")
   488  					Eventually(session).Should(Exit(0))
   489  				})
   490  
   491  				It("lists the labels", func() {
   492  					session := helpers.CF("labels", "stack", stackName)
   493  					Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for stack %s as %s...\n\n"), stackName, username))
   494  					Eventually(session).Should(Say(`key\s+value`))
   495  					Eventually(session).Should(Say(`some-key\s+some-value`))
   496  					Eventually(session).Should(Say(`some-other-key\s+some-other-value`))
   497  					Eventually(session).Should(Exit(0))
   498  				})
   499  			})
   500  
   501  			When("there are no labels set on the stack", func() {
   502  				It("indicates that there are no labels", func() {
   503  					session := helpers.CF("labels", "stack", stackName)
   504  					Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for stack %s as %s...\n\n"), stackName, username))
   505  					Expect(session).ToNot(Say(`key\s+value`))
   506  					Eventually(session).Should(Say("No labels found."))
   507  					Eventually(session).Should(Exit(0))
   508  				})
   509  			})
   510  
   511  			When("the stack does not exist", func() {
   512  				It("displays an error", func() {
   513  					session := helpers.CF("labels", "stack", "non-existent-stack")
   514  					Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for stack %s as %s...\n\n"), "non-existent-stack", username))
   515  					Eventually(session.Err).Should(Say("Stack 'non-existent-stack' not found"))
   516  					Eventually(session).Should(Say("FAILED"))
   517  					Eventually(session).Should(Exit(1))
   518  				})
   519  			})
   520  		})
   521  
   522  		Describe("space labels", func() {
   523  			BeforeEach(func() {
   524  				spaceName = helpers.NewSpaceName()
   525  				helpers.SetupCF(orgName, spaceName)
   526  			})
   527  			AfterEach(func() {
   528  				helpers.QuickDeleteOrg(orgName)
   529  			})
   530  
   531  			When("there are labels set on the space", func() {
   532  				BeforeEach(func() {
   533  					session := helpers.CF("set-label", "space", spaceName, "some-other-key=some-other-value", "some-key=some-value")
   534  					Eventually(session).Should(Exit(0))
   535  				})
   536  				It("lists the labels", func() {
   537  					session := helpers.CF("labels", "space", spaceName)
   538  					Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for space %s in org %s as %s...\n\n"), spaceName, orgName, username))
   539  					Eventually(session).Should(Say(`key\s+value`))
   540  					Eventually(session).Should(Say(`some-key\s+some-value`))
   541  					Eventually(session).Should(Say(`some-other-key\s+some-other-value`))
   542  					Eventually(session).Should(Exit(0))
   543  				})
   544  			})
   545  
   546  			When("there are no labels set on the space", func() {
   547  				It("indicates that there are no labels", func() {
   548  					session := helpers.CF("labels", "space", spaceName)
   549  					Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for space %s in org %s as %s...\n\n"), spaceName, orgName, username))
   550  					Expect(session).ToNot(Say(`key\s+value`))
   551  					Eventually(session).Should(Say("No labels found."))
   552  					Eventually(session).Should(Exit(0))
   553  				})
   554  			})
   555  
   556  			When("the space does not exist", func() {
   557  				It("displays an error", func() {
   558  					session := helpers.CF("labels", "space", "non-existent-space")
   559  					Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for space %s in org %s as %s...\n\n"), "non-existent-space", orgName, username))
   560  					Eventually(session.Err).Should(Say("Space 'non-existent-space' not found"))
   561  					Eventually(session).Should(Say("FAILED"))
   562  					Eventually(session).Should(Exit(1))
   563  				})
   564  			})
   565  		})
   566  	})
   567  })