github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+incompatible/integration/isolated/v3_push_command_test.go (about) 1 package isolated 2 3 import ( 4 "os" 5 6 "code.cloudfoundry.org/cli/integration/helpers" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gbytes" 10 . "github.com/onsi/gomega/gexec" 11 ) 12 13 var _ = Describe("v3-push command", func() { 14 var ( 15 orgName string 16 spaceName string 17 appName string 18 userName string 19 ) 20 21 BeforeEach(func() { 22 // TMP: this command also depends on https://www.pivotaltracker.com/story/show/146469509 23 Skip("don't run in the pipeline until cf-deployment master supports it") 24 25 orgName = helpers.NewOrgName() 26 spaceName = helpers.NewSpaceName() 27 appName = helpers.PrefixedRandomName("app") 28 userName, _ = helpers.GetCredentials() 29 }) 30 31 Describe("help", func() { 32 Context("when --help flag is set", func() { 33 It("Displays command usage to output", func() { 34 session := helpers.CF("v3-push", "--help") 35 Eventually(session.Out).Should(Say("NAME:")) 36 Eventually(session.Out).Should(Say("v3-push - Push a new app or sync changes to an existing app")) 37 Eventually(session.Out).Should(Say("USAGE:")) 38 Eventually(session.Out).Should(Say("cf v3-push APP_NAME")) 39 40 Eventually(session).Should(Exit(0)) 41 }) 42 }) 43 }) 44 45 Context("when the app name is not provided", func() { 46 It("tells the user that the app name is required, prints help text, and exits 1", func() { 47 session := helpers.CF("v3-push") 48 49 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided")) 50 Eventually(session.Out).Should(Say("NAME:")) 51 Eventually(session).Should(Exit(1)) 52 }) 53 }) 54 55 Context("when the environment is not setup correctly", func() { 56 Context("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-push", 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 Context("when not logged in", func() { 70 BeforeEach(func() { 71 helpers.LogoutCF() 72 }) 73 74 It("fails with not logged in message", func() { 75 session := helpers.CF("v3-push", appName) 76 Eventually(session).Should(Say("FAILED")) 77 Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\.")) 78 Eventually(session).Should(Exit(1)) 79 }) 80 }) 81 82 Context("when there is no org set", func() { 83 BeforeEach(func() { 84 helpers.LogoutCF() 85 helpers.LoginCF() 86 }) 87 88 It("fails with no org targeted error message", func() { 89 session := helpers.CF("v3-push", appName) 90 Eventually(session.Out).Should(Say("FAILED")) 91 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org\\.")) 92 Eventually(session).Should(Exit(1)) 93 }) 94 }) 95 96 Context("when there is no space set", func() { 97 BeforeEach(func() { 98 helpers.LogoutCF() 99 helpers.LoginCF() 100 helpers.TargetOrg(ReadOnlyOrg) 101 }) 102 103 It("fails with no space targeted error message", func() { 104 session := helpers.CF("v3-push", appName) 105 Eventually(session.Out).Should(Say("FAILED")) 106 Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space\\.")) 107 Eventually(session).Should(Exit(1)) 108 }) 109 }) 110 }) 111 112 Context("when the environment is set up correctly", func() { 113 var domainName string 114 115 BeforeEach(func() { 116 setupCF(orgName, spaceName) 117 118 domainName = defaultSharedDomain() 119 }) 120 121 Context("when the app exists", func() { 122 var session *Session 123 BeforeEach(func() { 124 helpers.WithHelloWorldApp(func(appDir string) { 125 err := os.Chdir(appDir) 126 Expect(err).ToNot(HaveOccurred()) 127 128 Eventually(helpers.CF("v3-push", appName)).Should(Exit(0)) 129 }) 130 131 helpers.WithHelloWorldApp(func(appDir string) { 132 err := os.Chdir(appDir) 133 Expect(err).ToNot(HaveOccurred()) 134 135 session = helpers.CF("v3-push", appName) 136 Eventually(session).Should(Exit(0)) 137 }) 138 }) 139 140 It("pushes the app", func() { 141 Eventually(session.Out).Should(Say("Updating app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 142 Eventually(session.Out).Should(Say("OK")) 143 Eventually(session.Out).Should(Say("")) 144 Eventually(session.Out).Should(Say("Uploading app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 145 Eventually(session.Out).Should(Say("OK")) 146 Eventually(session.Out).Should(Say("")) 147 Eventually(session.Out).Should(Say("Staging package for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 148 Eventually(session.Out).Should(Say(" Staging complete")) 149 Eventually(session.Out).Should(Say("droplet:")) 150 Eventually(session.Out).Should(Say("OK")) 151 Eventually(session.Out).Should(Say("Stopping app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 152 Eventually(session.Out).Should(Say("OK")) 153 Eventually(session.Out).Should(Say("")) 154 Eventually(session.Out).Should(Say("Setting app %s to droplet .+ in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 155 Eventually(session.Out).Should(Say("OK")) 156 Eventually(session.Out).Should(Say("")) 157 Eventually(session.Out).Should(Say("Mapping routes\\.\\.\\.")) 158 Eventually(session.Out).Should(Say("OK")) 159 Eventually(session.Out).Should(Say("")) 160 Eventually(session.Out).Should(Say("Starting app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 161 Eventually(session.Out).Should(Say("OK")) 162 Eventually(session.Out).Should(Say("")) 163 Eventually(session.Out).Should(Say("Waiting for app to start\\.\\.\\.")) 164 Eventually(session.Out).Should(Say("Showing health and status for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 165 Eventually(session.Out).Should(Say("")) 166 Eventually(session.Out).Should(Say("name:\\s+%s", appName)) 167 Eventually(session.Out).Should(Say("requested state:\\s+started")) 168 Eventually(session.Out).Should(Say("processes:\\s+web:1/1")) 169 Eventually(session.Out).Should(Say("memory usage:\\s+32M x 1")) 170 Eventually(session.Out).Should(Say("routes:\\s+%s\\.%s", appName, domainName)) 171 Eventually(session.Out).Should(Say("stack:\\s+cflinuxfs2")) 172 Eventually(session.Out).Should(Say("buildpacks:\\s+staticfile")) 173 Eventually(session.Out).Should(Say("")) 174 Eventually(session.Out).Should(Say("web:1/1")) 175 Eventually(session.Out).Should(Say(`state\s+since\s+cpu\s+memory\s+disk`)) 176 Eventually(session.Out).Should(Say("#0\\s+running\\s+\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2} [AP]M")) 177 }) 178 }) 179 180 Context("when the app does not already exist", func() { 181 var session *Session 182 183 BeforeEach(func() { 184 helpers.WithHelloWorldApp(func(appDir string) { 185 err := os.Chdir(appDir) 186 Expect(err).ToNot(HaveOccurred()) 187 188 session = helpers.CF("v3-push", appName) 189 Eventually(session).Should(Exit(0)) 190 }) 191 }) 192 193 It("pushes the app", func() { 194 Eventually(session.Out).Should(Say("Creating app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 195 Eventually(session.Out).Should(Say("OK")) 196 Eventually(session.Out).Should(Say("")) 197 Eventually(session.Out).Should(Say("Uploading app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 198 Eventually(session.Out).Should(Say("OK")) 199 Eventually(session.Out).Should(Say("")) 200 Eventually(session.Out).Should(Say("Staging package for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 201 Eventually(session.Out).Should(Say(" Staging complete")) 202 Eventually(session.Out).Should(Say("droplet:")) 203 Eventually(session.Out).Should(Say("OK")) 204 Consistently(session.Out).ShouldNot(Say("Stopping")) 205 Eventually(session.Out).Should(Say("Setting app %s to droplet .+ in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 206 Eventually(session.Out).Should(Say("OK")) 207 Eventually(session.Out).Should(Say("")) 208 Eventually(session.Out).Should(Say("Mapping routes\\.\\.\\.")) 209 Eventually(session.Out).Should(Say("OK")) 210 Eventually(session.Out).Should(Say("")) 211 Eventually(session.Out).Should(Say("Starting app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 212 Eventually(session.Out).Should(Say("OK")) 213 Eventually(session.Out).Should(Say("")) 214 Eventually(session.Out).Should(Say("Waiting for app to start\\.\\.\\.")) 215 Eventually(session.Out).Should(Say("Showing health and status for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName)) 216 Eventually(session.Out).Should(Say("")) 217 Eventually(session.Out).Should(Say("name:\\s+%s", appName)) 218 Eventually(session.Out).Should(Say("requested state:\\s+started")) 219 Eventually(session.Out).Should(Say("processes:\\s+web:1/1")) 220 Eventually(session.Out).Should(Say("memory usage:\\s+32M x 1")) 221 Eventually(session.Out).Should(Say("routes:\\s+%s\\.%s", appName, domainName)) 222 Eventually(session.Out).Should(Say("stack:\\s+cflinuxfs2")) 223 Eventually(session.Out).Should(Say("buildpacks:\\s+staticfile")) 224 Eventually(session.Out).Should(Say("")) 225 Eventually(session.Out).Should(Say("web:1/1")) 226 Eventually(session.Out).Should(Say(`state\s+since\s+cpu\s+memory\s+disk`)) 227 Eventually(session.Out).Should(Say("#0\\s+running\\s+\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2} [AP]M")) 228 }) 229 }) 230 231 Context("when the --no-route flag is set", func() { 232 var session *Session 233 234 BeforeEach(func() { 235 helpers.WithHelloWorldApp(func(appDir string) { 236 err := os.Chdir(appDir) 237 Expect(err).ToNot(HaveOccurred()) 238 239 session = helpers.CF("v3-push", appName, "--no-route") 240 Eventually(session).Should(Exit(0)) 241 }) 242 }) 243 244 It("does not map any routes to the app", func() { 245 Consistently(session.Out).ShouldNot(Say("Mapping routes\\.\\.\\.")) 246 Eventually(session.Out).Should(Say("name:\\s+%s", appName)) 247 Eventually(session.Out).Should(Say("requested state:\\s+started")) 248 Eventually(session.Out).Should(Say("processes:\\s+web:1/1")) 249 Eventually(session.Out).Should(Say("memory usage:\\s+32M x 1")) 250 Eventually(session.Out).Should(Say("routes:\\s+\n")) 251 Eventually(session.Out).Should(Say("stack:\\s+cflinuxfs2")) 252 Eventually(session.Out).Should(Say("buildpacks:\\s+staticfile")) 253 Eventually(session.Out).Should(Say("")) 254 Eventually(session.Out).Should(Say("web:1/1")) 255 Eventually(session.Out).Should(Say(`state\s+since\s+cpu\s+memory\s+disk`)) 256 Eventually(session.Out).Should(Say("#0\\s+running\\s+\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2} [AP]M")) 257 }) 258 }) 259 }) 260 })