github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v7/isolated/delete_org_command_test.go (about) 1 package isolated 2 3 import ( 4 . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" 5 "code.cloudfoundry.org/cli/integration/helpers" 6 . "github.com/onsi/ginkgo" 7 . "github.com/onsi/gomega" 8 . "github.com/onsi/gomega/gbytes" 9 . "github.com/onsi/gomega/gexec" 10 ) 11 12 var _ = Describe("delete-org command", func() { 13 Describe("help", func() { 14 When("--help flag is set", func() { 15 It("appears in cf help -a", func() { 16 session := helpers.CF("help", "-a") 17 Eventually(session).Should(Exit(0)) 18 Expect(session).To(HaveCommandInCategoryWithDescription("delete-org", "ORGS", "Delete an org")) 19 }) 20 21 It("Displays command usage to output", func() { 22 session := helpers.CF("delete-org", "--help") 23 Eventually(session).Should(Say("NAME:")) 24 Eventually(session).Should(Say("delete-org - Delete an org")) 25 Eventually(session).Should(Say("USAGE:")) 26 Eventually(session).Should(Say("cf delete-org ORG")) 27 Eventually(session).Should(Say("OPTIONS:")) 28 Eventually(session).Should(Say("-f Force deletion without confirmation")) 29 Eventually(session).Should(Say("SEE ALSO:")) 30 Eventually(session).Should(Say("create-org, orgs, quotas, set-org-role")) 31 Eventually(session).Should(Exit(0)) 32 }) 33 }) 34 }) 35 36 When("the environment is not setup correctly", func() { 37 It("fails with the appropriate errors", func() { 38 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "delete-org", "some-org") 39 }) 40 }) 41 42 When("the org name is not provided", func() { 43 It("displays an error and help", func() { 44 session := helpers.CF("delete-org") 45 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `ORG` was not provided")) 46 Eventually(session).Should(Say("USAGE")) 47 Eventually(session).Should(Exit(1)) 48 }) 49 }) 50 51 When("the org does not exist", func() { 52 BeforeEach(func() { 53 helpers.LoginCF() 54 }) 55 56 It("displays a warning and exits 0", func() { 57 username, _ := helpers.GetCredentials() 58 session := helpers.CF("delete-org", "-f", "please-do-not-exist-in-real-life") 59 Eventually(session).Should(Say("Deleting org please-do-not-exist-in-real-life as %s...", username)) 60 Eventually(session.Err).Should(Say(`Org 'please-do-not-exist-in-real-life' does not exist\.`)) 61 Eventually(session).Should(Say("OK")) 62 Eventually(session).Should(Exit(0)) 63 }) 64 }) 65 66 When("the org exists", func() { 67 var orgName string 68 69 BeforeEach(func() { 70 helpers.LoginCF() 71 72 orgName = helpers.NewOrgName() 73 helpers.CreateOrgAndSpace(orgName, helpers.NewSpaceName()) 74 }) 75 76 AfterEach(func() { 77 helpers.QuickDeleteOrgIfExists(orgName) 78 }) 79 80 When("the -f flag not is provided", func() { 81 var buffer *Buffer 82 83 BeforeEach(func() { 84 buffer = NewBuffer() 85 }) 86 87 When("the user enters 'y'", func() { 88 BeforeEach(func() { 89 _, err := buffer.Write([]byte("y\n")) 90 Expect(err).ToNot(HaveOccurred()) 91 }) 92 93 It("deletes the org", func() { 94 username, _ := helpers.GetCredentials() 95 session := helpers.CFWithStdin(buffer, "delete-org", orgName) 96 Eventually(session).Should(Say(`Really delete the org %s, including its spaces, apps, service instances, routes, private domains and space-scoped service brokers\?`, orgName)) 97 Eventually(session).Should(Say("Deleting org %s as %s...", orgName, username)) 98 Eventually(session).Should(Say("OK")) 99 Eventually(session).Should(Exit(0)) 100 Eventually(helpers.CF("org", orgName)).Should(Exit(1)) 101 }) 102 }) 103 104 When("the user enters 'n'", func() { 105 BeforeEach(func() { 106 _, err := buffer.Write([]byte("n\n")) 107 Expect(err).ToNot(HaveOccurred()) 108 }) 109 110 It("does not delete the org", func() { 111 session := helpers.CFWithStdin(buffer, "delete-org", orgName) 112 Eventually(session).Should(Say(`Really delete the org %s, including its spaces, apps, service instances, routes, private domains and space-scoped service brokers\?`, orgName)) 113 Eventually(session).Should(Say(`Organization '%s' has not been deleted\.`, orgName)) 114 Eventually(session).Should(Exit(0)) 115 Eventually(helpers.CF("org", orgName)).Should(Exit(0)) 116 }) 117 }) 118 119 When("the user enters the default input (hits return)", func() { 120 BeforeEach(func() { 121 _, err := buffer.Write([]byte("\n")) 122 Expect(err).ToNot(HaveOccurred()) 123 }) 124 125 It("does not delete the org", func() { 126 session := helpers.CFWithStdin(buffer, "delete-org", orgName) 127 Eventually(session).Should(Say(`Really delete the org %s, including its spaces, apps, service instances, routes, private domains and space-scoped service brokers\?`, orgName)) 128 Eventually(session).Should(Say(`Organization '%s' has not been deleted\.`, orgName)) 129 Eventually(session).Should(Exit(0)) 130 Eventually(helpers.CF("org", orgName)).Should(Exit(0)) 131 }) 132 }) 133 134 When("the user enters an invalid answer", func() { 135 BeforeEach(func() { 136 // The second '\n' is intentional. Otherwise the buffer will be 137 // closed while the interaction is still waiting for input; it gets 138 // an EOF and causes an error. 139 _, err := buffer.Write([]byte("wat\n\n")) 140 Expect(err).ToNot(HaveOccurred()) 141 }) 142 143 It("asks again", func() { 144 session := helpers.CFWithStdin(buffer, "delete-org", orgName) 145 Eventually(session).Should(Say(`Really delete the org %s, including its spaces, apps, service instances, routes, private domains and space-scoped service brokers\?`, orgName)) 146 Eventually(session).Should(Say(`invalid input \(not y, n, yes, or no\)`)) 147 Eventually(session).Should(Say(`Really delete the org %s, including its spaces, apps, service instances, routes, private domains and space-scoped service brokers\?`, orgName)) 148 Eventually(session).Should(Exit(0)) 149 Eventually(helpers.CF("org", orgName)).Should(Exit(0)) 150 }) 151 }) 152 }) 153 154 When("the -f flag is provided", func() { 155 It("deletes the org", func() { 156 username, _ := helpers.GetCredentials() 157 session := helpers.CF("delete-org", orgName, "-f") 158 Eventually(session).Should(Say("Deleting org %s as %s...", orgName, username)) 159 Eventually(session).Should(Say("OK")) 160 Eventually(session).Should(Exit(0)) 161 Eventually(helpers.CF("org", orgName)).Should(Exit(1)) 162 }) 163 }) 164 }) 165 166 When("deleting an org that is targeted", func() { 167 var orgName string 168 169 BeforeEach(func() { 170 helpers.LoginCF() 171 172 orgName = helpers.NewOrgName() 173 spaceName := helpers.NewSpaceName() 174 helpers.CreateOrgAndSpace(orgName, spaceName) 175 helpers.TargetOrgAndSpace(orgName, spaceName) 176 }) 177 178 AfterEach(func() { 179 helpers.QuickDeleteOrgIfExists(orgName) 180 }) 181 182 It("clears the targeted org and space", func() { 183 session := helpers.CF("delete-org", orgName, "-f") 184 Eventually(session).Should(Say("No org or space targeted, use 'cf target -o ORG -s SPACE'")) 185 Eventually(session).Should(Exit(0)) 186 }) 187 }) 188 189 When("deleting an org that is not targeted", func() { 190 var orgName string 191 192 BeforeEach(func() { 193 helpers.LoginCF() 194 195 orgName = helpers.NewOrgName() 196 helpers.TargetOrgAndSpace(ReadOnlyOrg, ReadOnlySpace) 197 }) 198 199 It("does not clear the targeted org and space", func() { 200 session := helpers.CF("delete-org", orgName, "-f") 201 Eventually(session).Should(Exit(0)) 202 203 session = helpers.CF("target") 204 Eventually(session).Should(Say(`org:\s+%s`, ReadOnlyOrg)) 205 Eventually(session).Should(Say(`space:\s+%s`, ReadOnlySpace)) 206 Eventually(session).Should(Exit(0)) 207 }) 208 }) 209 })