github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/isolated/delete_space_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-space command", func() { 12 Describe("help", func() { 13 It("shows usage", func() { 14 session := helpers.CF("help", "delete-space") 15 Eventually(session).Should(Say("NAME:")) 16 Eventually(session).Should(Say("\\s+delete-space - Delete a space")) 17 Eventually(session).Should(Say("USAGE:")) 18 Eventually(session).Should(Say("delete-space SPACE \\[-o ORG\\] \\[-f\\]")) 19 Eventually(session).Should(Say("OPTIONS:")) 20 Eventually(session).Should(Say("\\s+-f\\s+Force deletion without confirmation")) 21 Eventually(session).Should(Say("\\s+-o\\s+Delete space within specified org")) 22 Eventually(session).Should(Exit(0)) 23 }) 24 }) 25 26 Context("when the environment is not setup correctly", func() { 27 Context("when no API endpoint is set", func() { 28 BeforeEach(func() { 29 helpers.UnsetAPI() 30 }) 31 32 It("fails with no API endpoint set message", func() { 33 session := helpers.CF("delete-space", "banana") 34 Eventually(session.Out).Should(Say("FAILED")) 35 Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint.")) 36 Eventually(session).Should(Exit(1)) 37 }) 38 }) 39 40 Context("when not logged in", func() { 41 BeforeEach(func() { 42 helpers.LogoutCF() 43 }) 44 45 It("fails with not logged in message", func() { 46 session := helpers.CF("delete-space", "banana") 47 Eventually(session.Out).Should(Say("FAILED")) 48 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in.")) 49 Eventually(session).Should(Exit(1)) 50 }) 51 }) 52 }) 53 54 Context("when the space name it not provided", func() { 55 It("displays an error and help", func() { 56 session := helpers.CF("delete-space") 57 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SPACE` was not provided")) 58 Eventually(session.Out).Should(Say("USAGE")) 59 Eventually(session).Should(Exit(1)) 60 }) 61 }) 62 63 Context("when the space does not exist", func() { 64 var orgName string 65 66 BeforeEach(func() { 67 helpers.LoginCF() 68 69 orgName = helpers.NewOrgName() 70 helpers.CreateOrg(orgName) 71 }) 72 73 AfterEach(func() { 74 helpers.QuickDeleteOrg(orgName) 75 }) 76 77 It("fails and displays space not found", func() { 78 username, _ := helpers.GetCredentials() 79 session := helpers.CF("delete-space", "-f", "-o", orgName, "please-do-not-exist-in-real-life") 80 Eventually(session.Out).Should(Say("Deleting space please-do-not-exist-in-real-life in org %s as %s...", orgName, username)) 81 Eventually(session.Out).Should(Say("FAILED")) 82 Eventually(session.Err).Should(Say("Space 'please-do-not-exist-in-real-life' not found\\.")) 83 Eventually(session).Should(Exit(1)) 84 }) 85 }) 86 87 Context("when the space exists", func() { 88 var orgName string 89 var spaceName string 90 91 BeforeEach(func() { 92 helpers.LoginCF() 93 94 orgName = helpers.NewOrgName() 95 spaceName = helpers.NewSpaceName() 96 helpers.CreateOrgAndSpace(orgName, spaceName) 97 }) 98 99 AfterEach(func() { 100 helpers.QuickDeleteOrg(orgName) 101 }) 102 103 Context("when the -f flag not is provided", func() { 104 var buffer *Buffer 105 106 BeforeEach(func() { 107 buffer = NewBuffer() 108 }) 109 110 Context("when the user enters 'y'", func() { 111 BeforeEach(func() { 112 buffer.Write([]byte("y\n")) 113 }) 114 115 It("deletes the space", func() { 116 username, _ := helpers.GetCredentials() 117 session := helpers.CFWithStdin(buffer, "delete-space", spaceName) 118 Eventually(session.Out).Should(Say("Really delete the space %s\\? \\[yN\\]", spaceName)) 119 Eventually(session.Out).Should(Say("Deleting space %s in org %s as %s...", spaceName, orgName, username)) 120 Eventually(session.Out).Should(Say("OK")) 121 Eventually(session).Should(Exit(0)) 122 Eventually(helpers.CF("space", spaceName)).Should(Exit(1)) 123 }) 124 }) 125 126 Context("when the user enters 'n'", func() { 127 BeforeEach(func() { 128 buffer.Write([]byte("n\n")) 129 }) 130 131 It("does not delete the space", func() { 132 session := helpers.CFWithStdin(buffer, "delete-space", spaceName) 133 Eventually(session.Out).Should(Say("Really delete the space %s\\? \\[yN\\]", spaceName)) 134 Eventually(session.Out).Should(Say("Delete cancelled")) 135 Eventually(session).Should(Exit(0)) 136 Eventually(helpers.CF("space", spaceName)).Should(Exit(0)) 137 }) 138 }) 139 140 Context("when the user enters the default input (hits return)", func() { 141 BeforeEach(func() { 142 buffer.Write([]byte("\n")) 143 }) 144 145 It("does not delete the org", func() { 146 session := helpers.CFWithStdin(buffer, "delete-space", spaceName) 147 Eventually(session.Out).Should(Say("Really delete the space %s\\? \\[yN\\]", spaceName)) 148 Eventually(session.Out).Should(Say("Delete cancelled")) 149 Eventually(session).Should(Exit(0)) 150 Eventually(helpers.CF("space", spaceName)).Should(Exit(0)) 151 }) 152 }) 153 154 Context("when the user enters an invalid answer", func() { 155 BeforeEach(func() { 156 // The second '\n' is intentional. Otherwise the buffer will be 157 // closed while the interaction is still waiting for input; it gets 158 // an EOF and causes an error. 159 buffer.Write([]byte("wat\n\n")) 160 }) 161 162 It("asks again", func() { 163 session := helpers.CFWithStdin(buffer, "delete-space", spaceName) 164 Eventually(session.Out).Should(Say("Really delete the space %s\\? \\[yN\\]", spaceName)) 165 Eventually(session.Out).Should(Say("invalid input \\(not y, n, yes, or no\\)")) 166 Eventually(session.Out).Should(Say("Really delete the space %s\\? \\[yN\\]", spaceName)) 167 Eventually(session).Should(Exit(0)) 168 Eventually(helpers.CF("space", spaceName)).Should(Exit(0)) 169 }) 170 }) 171 }) 172 173 Context("when the -f flag is provided", func() { 174 It("deletes the space", func() { 175 username, _ := helpers.GetCredentials() 176 session := helpers.CF("delete-space", spaceName, "-f") 177 Eventually(session.Out).Should(Say("Deleting space %s in org %s as %s\\.\\.\\.", spaceName, orgName, username)) 178 Eventually(session.Out).Should(Say("OK")) 179 Eventually(session).Should(Exit(0)) 180 Eventually(helpers.CF("space", spaceName)).Should(Exit(1)) 181 }) 182 183 Context("when the space was targeted", func() { 184 BeforeEach(func() { 185 Eventually(helpers.CF("target", "-s", spaceName)).Should(Exit(0)) 186 }) 187 188 It("deletes the space and clears the target", func() { 189 username, _ := helpers.GetCredentials() 190 session := helpers.CF("delete-space", spaceName, "-f") 191 Eventually(session.Out).Should(Say("Deleting space %s in org %s as %s\\.\\.\\.", spaceName, orgName, username)) 192 Eventually(session.Out).Should(Say("OK")) 193 Eventually(session.Out).Should(Say("TIP: No space targeted, use 'cf target -s' to target a space\\.")) 194 Eventually(session).Should(Exit(0)) 195 196 Eventually(helpers.CF("space", spaceName)).Should(Exit(1)) 197 198 session = helpers.CF("target") 199 Eventually(session.Out).Should(Say("No space targeted, use 'cf target -s SPACE'")) 200 Eventually(session).Should(Exit(0)) 201 }) 202 }) 203 }) 204 }) 205 206 Context("when the -o organzation does not exist", func() { 207 BeforeEach(func() { 208 helpers.LoginCF() 209 }) 210 211 It("fails and displays org not found", func() { 212 username, _ := helpers.GetCredentials() 213 session := helpers.CF("delete-space", "-f", "-o", "please-do-not-exist-in-real-life", "please-do-not-exist-in-real-life") 214 Eventually(session.Out).Should(Say("Deleting space please-do-not-exist-in-real-life in org please-do-not-exist-in-real-life as %s...", username)) 215 Eventually(session.Err).Should(Say("Organization 'please-do-not-exist-in-real-life' not found\\.")) 216 Eventually(session.Out).Should(Say("FAILED")) 217 Eventually(session).Should(Exit(1)) 218 }) 219 }) 220 })