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