github.com/arunkumar7540/cli@v6.45.0+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 commonResource struct {
    43  			Metadata struct {
    44  				Labels map[string]string
    45  			}
    46  		}
    47  
    48  		BeforeEach(func() {
    49  			username, _ = helpers.GetCredentials()
    50  			helpers.LoginCF()
    51  			orgName = helpers.NewOrgName()
    52  			helpers.CreateOrg(orgName)
    53  		})
    54  
    55  		When("deleting labels from an app", func() {
    56  			BeforeEach(func() {
    57  				spaceName = helpers.NewSpaceName()
    58  				appName = helpers.PrefixedRandomName("app")
    59  
    60  				helpers.SetupCF(orgName, spaceName)
    61  				helpers.WithHelloWorldApp(func(appDir string) {
    62  					Eventually(helpers.CF("push", appName, "-p", appDir)).Should(Exit(0))
    63  				})
    64  
    65  				session := helpers.CF("set-label", "app", appName, "some-key=some-value", "some-other-key=some-other-value", "some-third-key=other")
    66  				Eventually(session).Should(Exit(0))
    67  			})
    68  
    69  			It("deletes the specified labels on the app", func() {
    70  				session := helpers.CF("delete-label", "app", appName, "some-other-key", "some-third-key")
    71  				Eventually(session).Should(Say(regexp.QuoteMeta(`Deleting label(s) for app %s in org %s / space %s as %s...`), appName, orgName, spaceName, username))
    72  				Consistently(session).ShouldNot(Say("\n\nOK"))
    73  				Eventually(session).Should(Say("OK"))
    74  				Eventually(session).Should(Exit(0))
    75  
    76  				appGuid := helpers.AppGUID(appName)
    77  				session = helpers.CF("curl", fmt.Sprintf("/v3/apps/%s", appGuid))
    78  				Eventually(session).Should(Exit(0))
    79  				appJSON := session.Out.Contents()
    80  
    81  				var app commonResource
    82  				Expect(json.Unmarshal(appJSON, &app)).To(Succeed())
    83  				Expect(len(app.Metadata.Labels)).To(Equal(1))
    84  				Expect(app.Metadata.Labels["some-key"]).To(Equal("some-value"))
    85  			})
    86  		})
    87  
    88  		When("Deleting labels from an org", func() {
    89  			BeforeEach(func() {
    90  				session := helpers.CF("set-label", "org", orgName, "pci=true", "public-facing=false")
    91  				Eventually(session).Should(Exit(0))
    92  			})
    93  
    94  			It("deletes the specified labels on the org", func() {
    95  				session := helpers.CF("delete-label", "org", orgName, "public-facing")
    96  				Eventually(session).Should(Say(regexp.QuoteMeta(`Deleting label(s) for org %s as %s...`), orgName, username))
    97  				Consistently(session).ShouldNot(Say("\n\nOK"))
    98  				Eventually(session).Should(Say("OK"))
    99  				Eventually(session).Should(Exit(0))
   100  
   101  				orgGUID := helpers.GetOrgGUID(orgName)
   102  				session = helpers.CF("curl", fmt.Sprintf("/v3/organizations/%s", orgGUID))
   103  				Eventually(session).Should(Exit(0))
   104  				orgJSON := session.Out.Contents()
   105  
   106  				var org commonResource
   107  				Expect(json.Unmarshal(orgJSON, &org)).To(Succeed())
   108  				Expect(len(org.Metadata.Labels)).To(Equal(1))
   109  				Expect(org.Metadata.Labels["pci"]).To(Equal("true"))
   110  			})
   111  
   112  		})
   113  	})
   114  })