github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/integration/isolated/delete_org_command_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/integration/helpers" 5 . "github.com/onsi/ginkgo" 6 . "github.com/onsi/gomega" 7 . "github.com/onsi/gomega/gbytes" 8 . "github.com/onsi/gomega/gexec" 9 ) 10 11 var _ = Describe("delete-org command", func() { 12 Context("when the environment is not setup correctly", func() { 13 Context("when no API endpoint is set", func() { 14 BeforeEach(func() { 15 helpers.UnsetAPI() 16 }) 17 18 It("fails with no API endpoint set message", func() { 19 session := helpers.CF("delete-org", "banana") 20 Eventually(session.Out).Should(Say("FAILED")) 21 Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint.")) 22 Eventually(session).Should(Exit(1)) 23 }) 24 }) 25 26 Context("when not logged in", func() { 27 BeforeEach(func() { 28 helpers.LogoutCF() 29 }) 30 31 It("fails with not logged in message", func() { 32 session := helpers.CF("delete-org", "banana") 33 Eventually(session.Out).Should(Say("FAILED")) 34 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in.")) 35 Eventually(session).Should(Exit(1)) 36 }) 37 }) 38 }) 39 40 Context("when the org name it not provided", func() { 41 It("displays an error and help", func() { 42 session := helpers.CF("delete-org") 43 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `ORG` was not provided")) 44 Eventually(session.Out).Should(Say("USAGE")) 45 Eventually(session).Should(Exit(1)) 46 }) 47 }) 48 49 Context("when the org does not exist", func() { 50 BeforeEach(func() { 51 helpers.LoginCF() 52 }) 53 54 It("displays a warning and exits 0", func() { 55 username, _ := helpers.GetCredentials() 56 session := helpers.CF("delete-org", "-f", "please-do-not-exist-in-real-life") 57 Eventually(session.Out).Should(Say("Deleting org please-do-not-exist-in-real-life as %s...", username)) 58 Eventually(session.Out).Should(Say("Org please-do-not-exist-in-real-life does not exist.")) 59 Eventually(session.Out).Should(Say("OK")) 60 Eventually(session).Should(Exit(0)) 61 }) 62 }) 63 64 Context("when the org exists", func() { 65 var orgName string 66 67 BeforeEach(func() { 68 helpers.LoginCF() 69 70 orgName = helpers.NewOrgName() 71 helpers.CreateOrgAndSpace(orgName, helpers.PrefixedRandomName("space")) 72 }) 73 74 Context("when the -f flag not is provided", func() { 75 var buffer *Buffer 76 77 BeforeEach(func() { 78 buffer = NewBuffer() 79 }) 80 81 Context("when the user enters 'y'", func() { 82 BeforeEach(func() { 83 buffer.Write([]byte("y\n")) 84 }) 85 86 It("deletes the org", func() { 87 username, _ := helpers.GetCredentials() 88 session := helpers.CFWithStdin(buffer, "delete-org", orgName) 89 Eventually(session.Out).Should(Say("Really delete the org %s and everything associated with it\\?>", orgName)) 90 Eventually(session.Out).Should(Say("Deleting org %s as %s...", orgName, username)) 91 Eventually(session.Out).Should(Say("OK")) 92 Eventually(session).Should(Exit(0)) 93 Eventually(helpers.CF("org", orgName)).Should(Exit(1)) 94 }) 95 }) 96 97 Context("when the user enters 'n'", func() { 98 BeforeEach(func() { 99 buffer.Write([]byte("n\n")) 100 }) 101 102 It("does not delete the org", func() { 103 session := helpers.CFWithStdin(buffer, "delete-org", orgName) 104 Eventually(session.Out).Should(Say("Really delete the org %s and everything associated with it\\?>", orgName)) 105 Eventually(session.Out).Should(Say("Delete cancelled")) 106 Eventually(session).Should(Exit(0)) 107 Eventually(helpers.CF("org", orgName)).Should(Exit(0)) 108 }) 109 }) 110 111 Context("when the user enters the default input (hits return)", func() { 112 BeforeEach(func() { 113 buffer.Write([]byte("\n")) 114 }) 115 116 It("does not delete the org", func() { 117 session := helpers.CFWithStdin(buffer, "delete-org", orgName) 118 Eventually(session.Out).Should(Say("Really delete the org %s and everything associated with it\\?>", orgName)) 119 Eventually(session.Out).Should(Say("Delete cancelled")) 120 Eventually(session).Should(Exit(0)) 121 Eventually(helpers.CF("org", orgName)).Should(Exit(0)) 122 }) 123 }) 124 125 Context("when the user enters an invalid answer", func() { 126 BeforeEach(func() { 127 // The second '\n' is intentional. Otherwise the buffer will be 128 // closed while the interaction is still waiting for input; it gets 129 // an EOF and causes an error. 130 buffer.Write([]byte("wat\n\n")) 131 }) 132 133 It("asks again", func() { 134 session := helpers.CFWithStdin(buffer, "delete-org", orgName) 135 Eventually(session.Out).Should(Say("Really delete the org %s and everything associated with it\\?>", orgName)) 136 Eventually(session.Out).Should(Say("invalid input \\(not y, n, yes, or no\\)")) 137 Eventually(session.Out).Should(Say("Really delete the org %s and everything associated with it\\?>", orgName)) 138 Eventually(session).Should(Exit(0)) 139 Eventually(helpers.CF("org", orgName)).Should(Exit(0)) 140 }) 141 }) 142 }) 143 144 Context("when the -f flag is provided", func() { 145 It("deletes the org", func() { 146 username, _ := helpers.GetCredentials() 147 session := helpers.CF("delete-org", orgName, "-f") 148 Eventually(session.Out).Should(Say("Deleting org %s as %s...", orgName, username)) 149 Eventually(session.Out).Should(Say("OK")) 150 Eventually(session).Should(Exit(0)) 151 Eventually(helpers.CF("org", orgName)).Should(Exit(1)) 152 }) 153 }) 154 }) 155 156 Context("when deleting an org that is targeted", func() { 157 var orgName string 158 159 BeforeEach(func() { 160 helpers.LoginCF() 161 162 orgName = helpers.NewOrgName() 163 spaceName := helpers.PrefixedRandomName("space") 164 helpers.CreateOrgAndSpace(orgName, spaceName) 165 helpers.TargetOrgAndSpace(orgName, spaceName) 166 }) 167 168 It("clears the targeted org and space", func() { 169 session := helpers.CF("delete-org", orgName, "-f") 170 Eventually(session).Should(Exit(0)) 171 172 session = helpers.CF("target") 173 Eventually(session.Out).Should(Say("No org or space targeted, use 'cf target -o ORG -s SPACE'")) 174 Eventually(session).Should(Exit(0)) 175 }) 176 }) 177 178 Context("when deleting an org that is not targeted", func() { 179 var orgName string 180 181 BeforeEach(func() { 182 helpers.LoginCF() 183 184 orgName = helpers.NewOrgName() 185 helpers.TargetOrgAndSpace(ReadOnlyOrg, ReadOnlySpace) 186 }) 187 188 It("does not clear the targeted org and space", func() { 189 session := helpers.CF("delete-org", orgName, "-f") 190 Eventually(session).Should(Exit(0)) 191 192 session = helpers.CF("target") 193 Eventually(session.Out).Should(Say("Org: %s", ReadOnlyOrg)) 194 Eventually(session.Out).Should(Say("Space: %s", ReadOnlySpace)) 195 Eventually(session).Should(Exit(0)) 196 }) 197 }) 198 })