github.com/willmadison/cli@v6.40.1-0.20181018160101-29d5937903ff+incompatible/integration/shared/experimental/v3_cancel_zdt_push_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-cancel-zdt-push 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.NewAppName() 23 helpers.TurnOffExperimental() 24 }) 25 26 AfterEach(func() { 27 helpers.TurnOnExperimental() 28 }) 29 30 Describe("help", func() { 31 Context("when --help flag is set", func() { 32 It("Displays command usage to output", func() { 33 session := helpers.CF("v3-cancel-zdt-push", "--help") 34 Eventually(session).Should(Say("NAME:")) 35 Eventually(session).Should(Say("v3-cancel-zdt-push - Cancel the most recent deployment for an app")) 36 Eventually(session).Should(Say("USAGE:")) 37 Eventually(session).Should(Say("cf v3-cancel-zdt-push APP_NAME")) 38 Eventually(session).Should(Exit(0)) 39 }) 40 }) 41 }) 42 43 Context("when the environment is not setup correctly", func() { 44 Context("when no API endpoint is set", func() { 45 BeforeEach(func() { 46 helpers.UnsetAPI() 47 }) 48 49 It("fails with no API endpoint set message", func() { 50 session := helpers.CF("v3-cancel-zdt-push", appName) 51 Eventually(session).Should(Say("FAILED")) 52 Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\.")) 53 Eventually(session).Should(Exit(1)) 54 }) 55 }) 56 57 When("the v3 api version is lower than the minimum version", func() { 58 var server *Server 59 60 BeforeEach(func() { 61 server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, "3.0.0") 62 }) 63 64 AfterEach(func() { 65 server.Close() 66 }) 67 68 It("fails with error message that the minimum version is not met", func() { 69 session := helpers.CF("v3-cancel-zdt-push", appName) 70 Eventually(session).Should(Say("FAILED")) 71 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\.")) 72 Eventually(session).Should(Exit(1)) 73 }) 74 }) 75 76 Context("when not logged in", func() { 77 BeforeEach(func() { 78 helpers.LogoutCF() 79 }) 80 81 It("fails with not logged in message", func() { 82 session := helpers.CF("v3-cancel-zdt-push", appName) 83 Eventually(session).Should(Say("FAILED")) 84 Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\.")) 85 Eventually(session).Should(Exit(1)) 86 }) 87 }) 88 89 Context("when there is no org set", func() { 90 BeforeEach(func() { 91 helpers.LogoutCF() 92 helpers.LoginCF() 93 }) 94 95 It("fails with no org targeted error message", func() { 96 session := helpers.CF("v3-cancel-zdt-push", appName) 97 Eventually(session).Should(Say("FAILED")) 98 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org\\.")) 99 Eventually(session).Should(Exit(1)) 100 }) 101 }) 102 103 Context("when there is no space set", func() { 104 BeforeEach(func() { 105 helpers.LogoutCF() 106 helpers.LoginCF() 107 helpers.TargetOrg(ReadOnlyOrg) 108 }) 109 110 It("fails with no space targeted error message", func() { 111 session := helpers.CF("v3-cancel-zdt-push", appName) 112 Eventually(session).Should(Say("FAILED")) 113 Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space\\.")) 114 Eventually(session).Should(Exit(1)) 115 }) 116 }) 117 }) 118 119 Context("when the environment is set up correctly", func() { 120 121 BeforeEach(func() { 122 helpers.SetupCF(orgName, spaceName) 123 }) 124 125 AfterEach(func() { 126 helpers.QuickDeleteOrg(orgName) 127 }) 128 129 Context("when the app name is not provided", func() { 130 It("tells the user that the app name is required, prints help text, and exits 1", func() { 131 session := helpers.CF("v3-cancel-zdt-push") 132 133 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided")) 134 Eventually(session).Should(Say("NAME:")) 135 Eventually(session).Should(Exit(1)) 136 }) 137 }) 138 139 It("displays the experimental warning", func() { 140 session := helpers.CF("v3-cancel-zdt-push", appName) 141 Eventually(session.Err).Should(Say("This command is in EXPERIMENTAL stage and may change without notice")) 142 Eventually(session).Should(Exit()) 143 }) 144 145 Context("when there is no org set", func() { 146 BeforeEach(func() { 147 helpers.LogoutCF() 148 helpers.LoginCF() 149 }) 150 151 It("fails with no org targeted error message", func() { 152 session := helpers.CF("v3-cancel-zdt-push", appName) 153 Eventually(session).Should(Say("FAILED")) 154 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org\\.")) 155 Eventually(session).Should(Exit(1)) 156 }) 157 }) 158 159 Context("when there is no space set", func() { 160 BeforeEach(func() { 161 helpers.LogoutCF() 162 helpers.LoginCF() 163 helpers.TargetOrg(ReadOnlyOrg) 164 }) 165 166 It("fails with no space targeted error message", func() { 167 session := helpers.CF("v3-cancel-zdt-push", appName) 168 Eventually(session).Should(Say("FAILED")) 169 Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space\\.")) 170 Eventually(session).Should(Exit(1)) 171 }) 172 }) 173 174 Context("when there is no org set", func() { 175 BeforeEach(func() { 176 helpers.LogoutCF() 177 helpers.LoginCF() 178 }) 179 180 It("fails with no org targeted error message", func() { 181 session := helpers.CF("v3-cancel-zdt-push", appName) 182 Eventually(session).Should(Say("FAILED")) 183 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org\\.")) 184 Eventually(session).Should(Exit(1)) 185 }) 186 }) 187 188 Context("when there is no space set", func() { 189 BeforeEach(func() { 190 helpers.LogoutCF() 191 helpers.LoginCF() 192 helpers.TargetOrg(ReadOnlyOrg) 193 }) 194 195 It("fails with no space targeted error message", func() { 196 session := helpers.CF("v3-cancel-zdt-push", appName) 197 Eventually(session).Should(Say("FAILED")) 198 Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space\\.")) 199 Eventually(session).Should(Exit(1)) 200 }) 201 }) 202 203 Context("when there is no org set", func() { 204 BeforeEach(func() { 205 helpers.LogoutCF() 206 helpers.LoginCF() 207 }) 208 209 It("fails with no org targeted error message", func() { 210 session := helpers.CF("v3-cancel-zdt-push", appName) 211 Eventually(session).Should(Say("FAILED")) 212 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org\\.")) 213 Eventually(session).Should(Exit(1)) 214 }) 215 }) 216 217 Context("when there is no space set", func() { 218 BeforeEach(func() { 219 helpers.LogoutCF() 220 helpers.LoginCF() 221 helpers.TargetOrg(ReadOnlyOrg) 222 }) 223 224 It("fails with no space targeted error message", func() { 225 session := helpers.CF("v3-cancel-zdt-push", appName) 226 Eventually(session).Should(Say("FAILED")) 227 Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space\\.")) 228 Eventually(session).Should(Exit(1)) 229 }) 230 }) 231 232 Context("when the app exists", func() { 233 var session *Session 234 235 BeforeEach(func() { 236 helpers.WithHelloWorldApp(func(appDir string) { 237 session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName) 238 Eventually(session).Should(Exit(0)) 239 }) 240 }) 241 242 Context("and it is currently deploying", func() { 243 BeforeEach(func() { 244 // zdt-push a crashing app so that underlying deployment never goes from DEPLOYING -> DEPLOYED 245 helpers.WithCrashingApp(func(appDir string) { 246 session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-zdt-push", appName) 247 Eventually(session).Should(Exit(0)) 248 }) 249 }) 250 251 It("cancels the deployment", func() { 252 session := helpers.CF("v3-cancel-zdt-push", appName) 253 Eventually(session).Should(Exit(0)) 254 Eventually(session).Should(Say("Deployment cancelled, rolling back")) 255 }) 256 }) 257 258 Context("when the app has no deployment to cancel", func() { 259 It("errors", func() { 260 session := helpers.CF("v3-cancel-zdt-push", appName) 261 Eventually(session).Should(Exit(1)) 262 Eventually(session.Err).Should(Say("failed to find a deployment for that app")) 263 }) 264 }) 265 }) 266 }) 267 })