github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+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 the org is provided", func() { 28 It("fails with the appropriate errors", func() { 29 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "delete-space", "space-name", "-o", ReadOnlyOrg) 30 }) 31 }) 32 33 Context("when the org is not provided", func() { 34 It("fails with the appropriate errors", func() { 35 helpers.CheckEnvironmentTargetedCorrectly(true, false, ReadOnlyOrg, "delete-space", "space-name") 36 }) 37 }) 38 }) 39 40 Context("when the space name it not provided", func() { 41 It("displays an error and help", func() { 42 session := helpers.CF("delete-space") 43 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SPACE` was not provided")) 44 Eventually(session).Should(Say("USAGE")) 45 Eventually(session).Should(Exit(1)) 46 }) 47 }) 48 49 Context("when the space does not exist", func() { 50 var orgName string 51 52 BeforeEach(func() { 53 helpers.LoginCF() 54 55 orgName = helpers.NewOrgName() 56 helpers.CreateOrg(orgName) 57 }) 58 59 AfterEach(func() { 60 helpers.QuickDeleteOrg(orgName) 61 }) 62 63 It("fails and displays space not found", func() { 64 username, _ := helpers.GetCredentials() 65 session := helpers.CF("delete-space", "-f", "-o", orgName, "please-do-not-exist-in-real-life") 66 Eventually(session).Should(Say("Deleting space please-do-not-exist-in-real-life in org %s as %s...", orgName, username)) 67 Eventually(session).Should(Say("FAILED")) 68 Eventually(session.Err).Should(Say("Space 'please-do-not-exist-in-real-life' not found\\.")) 69 Eventually(session).Should(Exit(1)) 70 }) 71 }) 72 73 Context("when the space exists", func() { 74 var orgName string 75 var spaceName string 76 77 BeforeEach(func() { 78 helpers.LoginCF() 79 80 orgName = helpers.NewOrgName() 81 spaceName = helpers.NewSpaceName() 82 helpers.CreateOrgAndSpace(orgName, spaceName) 83 }) 84 85 AfterEach(func() { 86 helpers.QuickDeleteOrg(orgName) 87 }) 88 89 Context("when the -f flag not is provided", func() { 90 var buffer *Buffer 91 92 BeforeEach(func() { 93 buffer = NewBuffer() 94 }) 95 96 Context("when the user enters 'y'", func() { 97 BeforeEach(func() { 98 buffer.Write([]byte("y\n")) 99 }) 100 101 It("deletes the space", func() { 102 username, _ := helpers.GetCredentials() 103 session := helpers.CFWithStdin(buffer, "delete-space", spaceName) 104 Eventually(session).Should(Say("Really delete the space %s\\? \\[yN\\]", spaceName)) 105 Eventually(session).Should(Say("Deleting space %s in org %s as %s...", spaceName, orgName, username)) 106 Eventually(session).Should(Say("OK")) 107 Eventually(session).Should(Exit(0)) 108 Eventually(helpers.CF("space", spaceName)).Should(Exit(1)) 109 }) 110 }) 111 112 Context("when the user enters 'n'", func() { 113 BeforeEach(func() { 114 buffer.Write([]byte("n\n")) 115 }) 116 117 It("does not delete the space", func() { 118 session := helpers.CFWithStdin(buffer, "delete-space", spaceName) 119 Eventually(session).Should(Say("Really delete the space %s\\? \\[yN\\]", spaceName)) 120 Eventually(session).Should(Say("Delete cancelled")) 121 Eventually(session).Should(Exit(0)) 122 Eventually(helpers.CF("space", spaceName)).Should(Exit(0)) 123 }) 124 }) 125 126 Context("when the user enters the default input (hits return)", func() { 127 BeforeEach(func() { 128 buffer.Write([]byte("\n")) 129 }) 130 131 It("does not delete the org", func() { 132 session := helpers.CFWithStdin(buffer, "delete-space", spaceName) 133 Eventually(session).Should(Say("Really delete the space %s\\? \\[yN\\]", spaceName)) 134 Eventually(session).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 an invalid answer", func() { 141 BeforeEach(func() { 142 // The second '\n' is intentional. Otherwise the buffer will be 143 // closed while the interaction is still waiting for input; it gets 144 // an EOF and causes an error. 145 buffer.Write([]byte("wat\n\n")) 146 }) 147 148 It("asks again", func() { 149 session := helpers.CFWithStdin(buffer, "delete-space", spaceName) 150 Eventually(session).Should(Say("Really delete the space %s\\? \\[yN\\]", spaceName)) 151 Eventually(session).Should(Say("invalid input \\(not y, n, yes, or no\\)")) 152 Eventually(session).Should(Say("Really delete the space %s\\? \\[yN\\]", spaceName)) 153 Eventually(session).Should(Exit(0)) 154 Eventually(helpers.CF("space", spaceName)).Should(Exit(0)) 155 }) 156 }) 157 }) 158 159 Context("when the -f flag is provided", func() { 160 It("deletes the space", func() { 161 username, _ := helpers.GetCredentials() 162 session := helpers.CF("delete-space", spaceName, "-f") 163 Eventually(session).Should(Say("Deleting space %s in org %s as %s\\.\\.\\.", spaceName, orgName, username)) 164 Eventually(session).Should(Say("OK")) 165 Eventually(session).Should(Exit(0)) 166 Eventually(helpers.CF("space", spaceName)).Should(Exit(1)) 167 }) 168 169 Context("when the space was targeted", func() { 170 BeforeEach(func() { 171 Eventually(helpers.CF("target", "-s", spaceName)).Should(Exit(0)) 172 }) 173 174 It("deletes the space and clears the target", func() { 175 username, _ := helpers.GetCredentials() 176 session := helpers.CF("delete-space", spaceName, "-f") 177 Eventually(session).Should(Say("Deleting space %s in org %s as %s\\.\\.\\.", spaceName, orgName, username)) 178 Eventually(session).Should(Say("OK")) 179 Eventually(session).Should(Say("TIP: No space targeted, use 'cf target -s' to target a space\\.")) 180 Eventually(session).Should(Exit(0)) 181 182 Eventually(helpers.CF("space", spaceName)).Should(Exit(1)) 183 184 session = helpers.CF("target") 185 Eventually(session).Should(Say("No space targeted, use 'cf target -s SPACE'")) 186 Eventually(session).Should(Exit(0)) 187 }) 188 }) 189 }) 190 }) 191 192 Context("when the -o organzation does not exist", func() { 193 BeforeEach(func() { 194 helpers.LoginCF() 195 }) 196 197 It("fails and displays org not found", func() { 198 username, _ := helpers.GetCredentials() 199 session := helpers.CF("delete-space", "-f", "-o", "please-do-not-exist-in-real-life", "please-do-not-exist-in-real-life") 200 Eventually(session).Should(Say("Deleting space please-do-not-exist-in-real-life in org please-do-not-exist-in-real-life as %s...", username)) 201 Eventually(session.Err).Should(Say("Organization 'please-do-not-exist-in-real-life' not found\\.")) 202 Eventually(session).Should(Say("FAILED")) 203 Eventually(session).Should(Exit(1)) 204 }) 205 }) 206 })