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