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