github.com/cloudfoundry-community/cloudfoundry-cli@v6.44.1-0.20240130060226-cda5ed8e89a5+incompatible/integration/v7/isolated/labels_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"regexp"
     5  
     6  	"code.cloudfoundry.org/cli/integration/helpers"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  	. "github.com/onsi/gomega/gbytes"
    10  	. "github.com/onsi/gomega/gexec"
    11  )
    12  
    13  var _ = Describe("labels command", func() {
    14  	When("--help flag is given", func() {
    15  		It("Displays command usage", func() {
    16  			session := helpers.CF("labels", "--help")
    17  
    18  			Eventually(session).Should(Say("NAME:"))
    19  			Eventually(session).Should(Say(`\s+labels - List all labels \(key-value pairs\) for an API resource`))
    20  			Eventually(session).Should(Say("USAGE:"))
    21  			Eventually(session).Should(Say(`\s+cf labels RESOURCE RESOURCE_NAME`))
    22  			Eventually(session).Should(Say("EXAMPLES:"))
    23  			Eventually(session).Should(Say(`\s+cf labels app dora`))
    24  			Eventually(session).Should(Say("RESOURCES:"))
    25  			Eventually(session).Should(Say(`\s+app`))
    26  			Eventually(session).Should(Say("SEE ALSO:"))
    27  			Eventually(session).Should(Say(`\s+set-label, delete-label`))
    28  			Eventually(session).Should(Exit(0))
    29  		})
    30  	})
    31  
    32  	When("the environment is set up correctly", func() {
    33  		var (
    34  			orgName   string
    35  			spaceName string
    36  			appName   string
    37  			username  string
    38  		)
    39  
    40  		BeforeEach(func() {
    41  			orgName = helpers.NewOrgName()
    42  			spaceName = helpers.NewSpaceName()
    43  			appName = helpers.PrefixedRandomName("app")
    44  
    45  			username, _ = helpers.GetCredentials()
    46  			helpers.SetupCF(orgName, spaceName)
    47  			helpers.WithHelloWorldApp(func(appDir string) {
    48  				Eventually(helpers.CF("push", appName, "-p", appDir)).Should(Exit(0))
    49  			})
    50  		})
    51  
    52  		When("there are labels set on the application", func() {
    53  			BeforeEach(func() {
    54  				session := helpers.CF("set-label", "app", appName, "some-other-key=some-other-value", "some-key=some-value")
    55  				Eventually(session).Should(Exit(0))
    56  			})
    57  			It("lists the labels", func() {
    58  				session := helpers.CF("labels", "app", appName)
    59  				Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for app %s in org %s / space %s as %s...\n\n"), appName, orgName, spaceName, username))
    60  				Eventually(session).Should(Say(`Key\s+Value`))
    61  				Eventually(session).Should(Say(`some-key\s+some-value`))
    62  				Eventually(session).Should(Say(`some-other-key\s+some-other-value`))
    63  				Eventually(session).Should(Exit(0))
    64  			})
    65  		})
    66  
    67  		When("there are no labels set on the application", func() {
    68  			It("indicates that there are no labels", func() {
    69  				session := helpers.CF("labels", "app", appName)
    70  				Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for app %s in org %s / space %s as %s...\n\n"), appName, orgName, spaceName, username))
    71  				Expect(session).ToNot(Say(`Key\s+Value`))
    72  				Eventually(session).Should(Say("No labels found."))
    73  				Eventually(session).Should(Exit(0))
    74  			})
    75  		})
    76  
    77  		When("the app does not exist", func() {
    78  			It("displays an error", func() {
    79  				session := helpers.CF("labels", "app", "non-existent-app")
    80  				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))
    81  				Eventually(session.Err).Should(Say("App 'non-existent-app' not found"))
    82  				Eventually(session).Should(Say("FAILED"))
    83  				Eventually(session).Should(Exit(1))
    84  			})
    85  		})
    86  	})
    87  })