github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/experimental/v3_delete_command_test.go (about) 1 package experimental 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 . "github.com/onsi/gomega/ghttp" 10 ) 11 12 var _ = Describe("v3-delete command", func() { 13 var ( 14 orgName string 15 spaceName string 16 appName string 17 ) 18 19 BeforeEach(func() { 20 orgName = helpers.NewOrgName() 21 spaceName = helpers.NewSpaceName() 22 appName = helpers.PrefixedRandomName("app") 23 }) 24 25 Context("when --help flag is set", func() { 26 It("Displays command usage to output", func() { 27 session := helpers.CF("v3-delete", "--help") 28 Eventually(session).Should(Say("NAME:")) 29 Eventually(session).Should(Say("v3-delete - Delete a V3 App")) 30 Eventually(session).Should(Say("USAGE:")) 31 Eventually(session).Should(Say("cf v3-delete APP_NAME \\[-f\\]")) 32 Eventually(session).Should(Say("OPTIONS:")) 33 Eventually(session).Should(Say("\\s+-f\\s+Force deletion without confirmation")) 34 Eventually(session).Should(Exit(0)) 35 }) 36 }) 37 38 Context("when the app name is not provided", func() { 39 It("tells the user that the app name is required, prints help text, and exits 1", func() { 40 session := helpers.CF("v3-delete") 41 42 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided")) 43 Eventually(session).Should(Say("NAME:")) 44 Eventually(session).Should(Exit(1)) 45 }) 46 }) 47 48 It("displays the experimental warning", func() { 49 session := helpers.CF("v3-delete", appName) 50 Eventually(session).Should(Say("This command is in EXPERIMENTAL stage and may change without notice")) 51 Eventually(session).Should(Exit()) 52 }) 53 54 Context("when the environment is not setup correctly", func() { 55 Context("when no API endpoint is set", func() { 56 BeforeEach(func() { 57 helpers.UnsetAPI() 58 }) 59 60 It("fails with no API endpoint set message", func() { 61 session := helpers.CF("v3-delete", appName) 62 Eventually(session).Should(Say("FAILED")) 63 Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint.")) 64 Eventually(session).Should(Exit(1)) 65 }) 66 }) 67 68 Context("when the v3 api does not exist", func() { 69 var server *Server 70 71 BeforeEach(func() { 72 server = helpers.StartAndTargetServerWithoutV3API() 73 }) 74 75 AfterEach(func() { 76 server.Close() 77 }) 78 79 It("fails with error message that the minimum version is not met", func() { 80 session := helpers.CF("v3-delete", appName) 81 Eventually(session).Should(Say("FAILED")) 82 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\.")) 83 Eventually(session).Should(Exit(1)) 84 }) 85 }) 86 87 Context("when the v3 api version is lower than the minimum version", func() { 88 var server *Server 89 90 BeforeEach(func() { 91 server = helpers.StartAndTargetServerWithV3Version("3.0.0") 92 }) 93 94 AfterEach(func() { 95 server.Close() 96 }) 97 98 It("fails with error message that the minimum version is not met", func() { 99 session := helpers.CF("v3-delete", appName) 100 Eventually(session).Should(Say("FAILED")) 101 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\.")) 102 Eventually(session).Should(Exit(1)) 103 }) 104 }) 105 106 Context("when not logged in", func() { 107 BeforeEach(func() { 108 helpers.LogoutCF() 109 }) 110 111 It("fails with not logged in message", func() { 112 session := helpers.CF("v3-delete", appName) 113 Eventually(session).Should(Say("FAILED")) 114 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in.")) 115 Eventually(session).Should(Exit(1)) 116 }) 117 }) 118 119 Context("when there is no org set", func() { 120 BeforeEach(func() { 121 helpers.LogoutCF() 122 helpers.LoginCF() 123 }) 124 125 It("fails with no targeted org error message", func() { 126 session := helpers.CF("v3-delete", appName) 127 Eventually(session).Should(Say("FAILED")) 128 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org.")) 129 Eventually(session).Should(Exit(1)) 130 }) 131 }) 132 133 Context("when there is no space set", func() { 134 BeforeEach(func() { 135 helpers.LogoutCF() 136 helpers.LoginCF() 137 helpers.TargetOrg(ReadOnlyOrg) 138 }) 139 140 It("fails with no targeted space error message", func() { 141 session := helpers.CF("v3-delete", appName) 142 Eventually(session).Should(Say("FAILED")) 143 Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space.")) 144 Eventually(session).Should(Exit(1)) 145 }) 146 }) 147 }) 148 149 Context("when the environment is setup correctly", func() { 150 BeforeEach(func() { 151 setupCF(orgName, spaceName) 152 }) 153 154 AfterEach(func() { 155 helpers.QuickDeleteOrg(orgName) 156 }) 157 158 Context("when the app does not exist", func() { 159 Context("when the -f flag is provided", func() { 160 It("it displays the app does not exist", func() { 161 username, _ := helpers.GetCredentials() 162 session := helpers.CF("v3-delete", appName, "-f") 163 Eventually(session).Should(Say("Deleting app %s in org %s / space %s as %s...", appName, orgName, spaceName, username)) 164 Eventually(session).Should(Say("App %s does not exist", appName)) 165 Eventually(session).Should(Say("OK")) 166 Eventually(session).Should(Exit(0)) 167 }) 168 }) 169 170 Context("when the -f flag not is provided", func() { 171 var buffer *Buffer 172 173 BeforeEach(func() { 174 buffer = NewBuffer() 175 }) 176 177 Context("when the user enters 'y'", func() { 178 BeforeEach(func() { 179 buffer.Write([]byte("y\n")) 180 }) 181 182 It("it displays the app does not exist", func() { 183 username, _ := helpers.GetCredentials() 184 session := helpers.CFWithStdin(buffer, "v3-delete", appName) 185 Eventually(session).Should(Say("Really delete the app %s\\? \\[yN\\]", appName)) 186 Eventually(session).Should(Say("Deleting app %s in org %s / space %s as %s...", appName, orgName, spaceName, username)) 187 Eventually(session).Should(Say("App %s does not exist", appName)) 188 Eventually(session).Should(Say("OK")) 189 Eventually(session).Should(Exit(0)) 190 }) 191 }) 192 193 Context("when the user enters 'n'", func() { 194 BeforeEach(func() { 195 buffer.Write([]byte("n\n")) 196 }) 197 198 It("does not delete the app", func() { 199 session := helpers.CFWithStdin(buffer, "v3-delete", appName) 200 Eventually(session).Should(Say("Really delete the app %s\\? \\[yN\\]", appName)) 201 Eventually(session).Should(Say("Delete cancelled")) 202 Eventually(session).Should(Exit(0)) 203 }) 204 }) 205 206 Context("when the user enters the default input (hits return)", func() { 207 BeforeEach(func() { 208 buffer.Write([]byte("\n")) 209 }) 210 211 It("does not delete the app", func() { 212 session := helpers.CFWithStdin(buffer, "v3-delete", appName) 213 Eventually(session).Should(Say("Really delete the app %s\\? \\[yN\\]", appName)) 214 Eventually(session).Should(Say("Delete cancelled")) 215 Eventually(session).Should(Exit(0)) 216 }) 217 }) 218 219 Context("when the user enters an invalid answer", func() { 220 BeforeEach(func() { 221 // The second '\n' is intentional. Otherwise the buffer will be 222 // closed while the interaction is still waiting for input; it gets 223 // an EOF and causes an error. 224 buffer.Write([]byte("wat\n\n")) 225 }) 226 227 It("asks again", func() { 228 session := helpers.CFWithStdin(buffer, "v3-delete", appName) 229 Eventually(session).Should(Say("Really delete the app %s\\? \\[yN\\]", appName)) 230 Eventually(session).Should(Say("invalid input \\(not y, n, yes, or no\\)")) 231 Eventually(session).Should(Say("Really delete the app %s\\? \\[yN\\]", appName)) 232 Eventually(session).Should(Exit(0)) 233 }) 234 }) 235 }) 236 }) 237 238 Context("when the app exists", func() { 239 BeforeEach(func() { 240 helpers.WithHelloWorldApp(func(appDir string) { 241 Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)).Should(Exit(0)) 242 }) 243 }) 244 245 It("deletes the app", func() { 246 session := helpers.CF("v3-delete", appName, "-f") 247 username, _ := helpers.GetCredentials() 248 Eventually(session).Should(Say("Deleting app %s in org %s / space %s as %s...", appName, orgName, spaceName, username)) 249 Eventually(session).Should(Say("OK")) 250 Eventually(session).Should(Exit(0)) 251 252 Eventually(helpers.CF("v3-app", appName)).Should(Exit(1)) 253 }) 254 }) 255 }) 256 })