github.com/arunkumar7540/cli@v6.45.0+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(`\s+space`)) 27 Eventually(session).Should(Say(`\s+org`)) 28 Eventually(session).Should(Say("SEE ALSO:")) 29 Eventually(session).Should(Say(`\s+set-label, delete-label`)) 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 BeforeEach(func() { 43 orgName = helpers.NewOrgName() 44 username, _ = helpers.GetCredentials() 45 helpers.LoginCF() 46 helpers.CreateOrg(orgName) 47 }) 48 49 Describe("app labels", func() { 50 BeforeEach(func() { 51 helpers.TargetOrg(orgName) 52 spaceName = helpers.NewSpaceName() 53 appName = helpers.PrefixedRandomName("app") 54 helpers.CreateSpace(spaceName) 55 helpers.TargetOrgAndSpace(orgName, spaceName) 56 helpers.SetupCF(orgName, spaceName) 57 helpers.WithHelloWorldApp(func(appDir string) { 58 Eventually(helpers.CF("push", appName, "-p", appDir)).Should(Exit(0)) 59 }) 60 }) 61 62 When("there are labels set on the application", func() { 63 BeforeEach(func() { 64 session := helpers.CF("set-label", "app", appName, "some-other-key=some-other-value", "some-key=some-value") 65 Eventually(session).Should(Exit(0)) 66 }) 67 It("lists the labels", func() { 68 session := helpers.CF("labels", "app", appName) 69 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for app %s in org %s / space %s as %s...\n\n"), appName, orgName, spaceName, username)) 70 Eventually(session).Should(Say(`key\s+value`)) 71 Eventually(session).Should(Say(`some-key\s+some-value`)) 72 Eventually(session).Should(Say(`some-other-key\s+some-other-value`)) 73 Eventually(session).Should(Exit(0)) 74 }) 75 }) 76 77 When("there are no labels set on the application", func() { 78 It("indicates that there are no labels", func() { 79 session := helpers.CF("labels", "app", appName) 80 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for app %s in org %s / space %s as %s...\n\n"), appName, orgName, spaceName, username)) 81 Expect(session).ToNot(Say(`key\s+value`)) 82 Eventually(session).Should(Say("No labels found.")) 83 Eventually(session).Should(Exit(0)) 84 }) 85 }) 86 87 When("the app does not exist", func() { 88 It("displays an error", func() { 89 session := helpers.CF("labels", "app", "non-existent-app") 90 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)) 91 Eventually(session.Err).Should(Say("App 'non-existent-app' not found")) 92 Eventually(session).Should(Say("FAILED")) 93 Eventually(session).Should(Exit(1)) 94 }) 95 }) 96 }) 97 98 Describe("org labels", func() { 99 100 When("there are labels set on the organization", func() { 101 BeforeEach(func() { 102 session := helpers.CF("set-label", "org", orgName, "some-other-key=some-other-value", "some-key=some-value") 103 Eventually(session).Should(Exit(0)) 104 }) 105 It("lists the labels", func() { 106 session := helpers.CF("labels", "org", orgName) 107 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for org %s as %s...\n\n"), orgName, username)) 108 Eventually(session).Should(Say(`key\s+value`)) 109 Eventually(session).Should(Say(`some-key\s+some-value`)) 110 Eventually(session).Should(Say(`some-other-key\s+some-other-value`)) 111 Eventually(session).Should(Exit(0)) 112 }) 113 }) 114 115 When("there are no labels set on the organization", func() { 116 It("indicates that there are no labels", func() { 117 session := helpers.CF("labels", "org", orgName) 118 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for org %s as %s...\n\n"), orgName, username)) 119 Expect(session).ToNot(Say(`key\s+value`)) 120 Eventually(session).Should(Say("No labels found.")) 121 Eventually(session).Should(Exit(0)) 122 }) 123 }) 124 125 When("the org does not exist", func() { 126 It("displays an error", func() { 127 session := helpers.CF("labels", "org", "non-existent-org") 128 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for org %s as %s...\n\n"), "non-existent-org", username)) 129 Eventually(session.Err).Should(Say("Organization 'non-existent-org' not found")) 130 Eventually(session).Should(Say("FAILED")) 131 Eventually(session).Should(Exit(1)) 132 }) 133 }) 134 }) 135 136 Describe("space labels", func() { 137 BeforeEach(func() { 138 helpers.TargetOrg(orgName) 139 spaceName = helpers.NewSpaceName() 140 helpers.CreateSpace(spaceName) 141 helpers.TargetOrgAndSpace(orgName, spaceName) 142 helpers.SetupCF(orgName, spaceName) 143 }) 144 145 When("there are labels set on the space", func() { 146 BeforeEach(func() { 147 session := helpers.CF("set-label", "space", spaceName, "some-other-key=some-other-value", "some-key=some-value") 148 Eventually(session).Should(Exit(0)) 149 }) 150 It("lists the labels", func() { 151 session := helpers.CF("labels", "space", spaceName) 152 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for space %s in org %s as %s...\n\n"), spaceName, orgName, username)) 153 Eventually(session).Should(Say(`key\s+value`)) 154 Eventually(session).Should(Say(`some-key\s+some-value`)) 155 Eventually(session).Should(Say(`some-other-key\s+some-other-value`)) 156 Eventually(session).Should(Exit(0)) 157 }) 158 }) 159 160 When("there are no labels set on the space", func() { 161 It("indicates that there are no labels", func() { 162 session := helpers.CF("labels", "space", spaceName) 163 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for space %s in org %s as %s...\n\n"), spaceName, orgName, username)) 164 Expect(session).ToNot(Say(`key\s+value`)) 165 Eventually(session).Should(Say("No labels found.")) 166 Eventually(session).Should(Exit(0)) 167 }) 168 }) 169 170 When("the space does not exist", func() { 171 It("displays an error", func() { 172 session := helpers.CF("labels", "space", "non-existent-space") 173 Eventually(session).Should(Say(regexp.QuoteMeta("Getting labels for space %s in org %s as %s...\n\n"), "non-existent-space", orgName, username)) 174 Eventually(session.Err).Should(Say("Space 'non-existent-space' not found")) 175 Eventually(session).Should(Say("FAILED")) 176 Eventually(session).Should(Exit(1)) 177 }) 178 }) 179 }) 180 }) 181 })