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