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

     1  package isolated
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"regexp"
     7  
     8  	"code.cloudfoundry.org/cli/integration/helpers"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  	. "github.com/onsi/gomega/gbytes"
    12  	. "github.com/onsi/gomega/gexec"
    13  )
    14  
    15  var _ = Describe("delete-label command", func() {
    16  	When("--help flag is given", func() {
    17  		It("Displays command usage to output", func() {
    18  			session := helpers.CF("delete-label", "--help")
    19  
    20  			Eventually(session).Should(Say("NAME:"))
    21  			Eventually(session).Should(Say(`\s+delete-label - Delete a label \(key-value pairs\) for an API resource`))
    22  			Eventually(session).Should(Say("USAGE:"))
    23  			Eventually(session).Should(Say(`\s+cf delete-label RESOURCE RESOURCE_NAME KEY`))
    24  			Eventually(session).Should(Say("EXAMPLES:"))
    25  			Eventually(session).Should(Say(`\s+cf delete-label app dora ci_signature_sha2`))
    26  			Eventually(session).Should(Say("RESOURCES:"))
    27  			Eventually(session).Should(Say(`\s+app`))
    28  			Eventually(session).Should(Say("SEE ALSO:"))
    29  			Eventually(session).Should(Say(`\s+set-label, labels`))
    30  			Eventually(session).Should(Exit(0))
    31  		})
    32  	})
    33  
    34  	When("the environment is set up correctly", func() {
    35  		var (
    36  			orgName   string
    37  			spaceName string
    38  			appName   string
    39  			username  string
    40  		)
    41  
    42  		type AppResource struct {
    43  			Metadata struct {
    44  				Labels map[string]string
    45  			}
    46  		}
    47  
    48  		BeforeEach(func() {
    49  			orgName = helpers.NewOrgName()
    50  			spaceName = helpers.NewSpaceName()
    51  			appName = helpers.PrefixedRandomName("app")
    52  
    53  			username, _ = helpers.GetCredentials()
    54  			helpers.SetupCF(orgName, spaceName)
    55  			helpers.WithHelloWorldApp(func(appDir string) {
    56  				Eventually(helpers.CF("push", appName, "-p", appDir)).Should(Exit(0))
    57  			})
    58  
    59  			session := helpers.CF("set-label", "app", appName, "some-key=some-value", "some-other-key=some-other-value", "some-third-key=other")
    60  			Eventually(session).Should(Exit(0))
    61  		})
    62  
    63  		It("sets the specified labels on the app", func() {
    64  			session := helpers.CF("delete-label", "app", appName, "some-other-key", "some-third-key")
    65  			Eventually(session).Should(Say(regexp.QuoteMeta(`Deleting label(s) for app %s in org %s / space %s as %s...`), appName, orgName, spaceName, username))
    66  			Consistently(session).ShouldNot(Say("\n\nOK"))
    67  			Eventually(session).Should(Say("OK"))
    68  			Eventually(session).Should(Exit(0))
    69  
    70  			appGuid := helpers.AppGUID(appName)
    71  			session = helpers.CF("curl", fmt.Sprintf("/v3/apps/%s", appGuid))
    72  			Eventually(session).Should(Exit(0))
    73  			appJSON := session.Out.Contents()
    74  
    75  			var app AppResource
    76  			Expect(json.Unmarshal(appJSON, &app)).To(Succeed())
    77  			Expect(len(app.Metadata.Labels)).To(Equal(1))
    78  			Expect(app.Metadata.Labels["some-key"]).To(Equal("some-value"))
    79  		})
    80  	})
    81  })