github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/integration/isolated/start_command_test.go (about) 1 package isolated 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "path/filepath" 7 8 "code.cloudfoundry.org/cli/integration/helpers" 9 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 . "github.com/onsi/gomega/gbytes" 13 . "github.com/onsi/gomega/gexec" 14 ) 15 16 var _ = Describe("start command", func() { 17 BeforeEach(func() { 18 helpers.RunIfExperimental("start command refactor is still experimental") 19 }) 20 21 Describe("help", func() { 22 Context("when --help flag is set", func() { 23 It("Displays command usage to output", func() { 24 session := helpers.CF("start", "--help") 25 Eventually(session).Should(Say("NAME:")) 26 Eventually(session).Should(Say("start - Start an app")) 27 Eventually(session).Should(Say("USAGE:")) 28 Eventually(session).Should(Say("cf start APP_NAME")) 29 Eventually(session).Should(Say("ALIAS:")) 30 Eventually(session).Should(Say("st")) 31 Eventually(session).Should(Say("ENVIRONMENT:")) 32 Eventually(session).Should(Say("CF_STAGING_TIMEOUT=15\\s+Max wait time for buildpack staging, in minutes")) 33 Eventually(session).Should(Say("CF_STARTUP_TIMEOUT=5\\s+Max wait time for app instance startup, in minutes")) 34 Eventually(session).Should(Say("SEE ALSO:")) 35 Eventually(session).Should(Say("apps, logs, scale, ssh, stop, restart, run-task")) 36 Eventually(session).Should(Exit(0)) 37 }) 38 }) 39 }) 40 41 Context("when the environment is not setup correctly", func() { 42 Context("when no API endpoint is set", func() { 43 BeforeEach(func() { 44 helpers.UnsetAPI() 45 }) 46 47 It("fails with no API endpoint set message", func() { 48 session := helpers.CF("start", "wut") 49 Eventually(session.Out).Should(Say("FAILED")) 50 Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint.")) 51 Eventually(session).Should(Exit(1)) 52 }) 53 }) 54 55 Context("when not logged in", func() { 56 BeforeEach(func() { 57 helpers.LogoutCF() 58 }) 59 60 It("fails with not logged in message", func() { 61 session := helpers.CF("start", "wut") 62 Eventually(session.Out).Should(Say("FAILED")) 63 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in.")) 64 Eventually(session).Should(Exit(1)) 65 }) 66 }) 67 68 Context("when there is no org set", func() { 69 BeforeEach(func() { 70 helpers.LogoutCF() 71 helpers.LoginCF() 72 }) 73 74 It("fails with no targeted org error message", func() { 75 session := helpers.CF("start", "wut") 76 Eventually(session.Out).Should(Say("FAILED")) 77 Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org.")) 78 Eventually(session).Should(Exit(1)) 79 }) 80 }) 81 82 Context("when there is no space set", func() { 83 BeforeEach(func() { 84 helpers.LogoutCF() 85 helpers.LoginCF() 86 helpers.TargetOrg(ReadOnlyOrg) 87 }) 88 89 It("fails with no targeted space error message", func() { 90 session := helpers.CF("start", "wut") 91 Eventually(session.Out).Should(Say("FAILED")) 92 Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space.")) 93 Eventually(session).Should(Exit(1)) 94 }) 95 }) 96 }) 97 98 Context("when the environment is set up correctly", func() { 99 var ( 100 orgName string 101 spaceName string 102 ) 103 104 BeforeEach(func() { 105 orgName = helpers.NewOrgName() 106 spaceName = helpers.PrefixedRandomName("SPACE") 107 108 setupCF(orgName, spaceName) 109 }) 110 111 AfterEach(func() { 112 helpers.QuickDeleteOrg(orgName) 113 }) 114 115 Context("when the app does not exist", func() { 116 It("tells the user that the start is not found and exits 1", func() { 117 appName := helpers.PrefixedRandomName("app") 118 session := helpers.CF("start", appName) 119 120 Eventually(session.Out).Should(Say("FAILED")) 121 Eventually(session.Err).Should(Say("App %s not found", appName)) 122 Eventually(session).Should(Exit(1)) 123 }) 124 }) 125 126 Context("when the app does exist", func() { 127 var ( 128 domainName string 129 appName string 130 ) 131 132 Context("when the app is started", func() { 133 BeforeEach(func() { 134 appName = helpers.PrefixedRandomName("app") 135 domainName = defaultSharedDomain() 136 helpers.WithHelloWorldApp(func(appDir string) { 137 Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0)) 138 }) 139 }) 140 141 It("only displays the app already started message", func() { 142 userName, _ := helpers.GetCredentials() 143 session := helpers.CF("start", appName) 144 Eventually(session).Should(Say("Starting app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)) 145 Eventually(session).Should(Say("App %s is already started", appName)) 146 Eventually(session).Should(Exit(0)) 147 }) 148 }) 149 150 Context("when the app is stopped", func() { 151 Context("when the app has been staged", func() { 152 BeforeEach(func() { 153 appName = helpers.PrefixedRandomName("app") 154 domainName = defaultSharedDomain() 155 helpers.WithHelloWorldApp(func(appDir string) { 156 manifestContents := []byte(fmt.Sprintf(` 157 --- 158 applications: 159 - name: %s 160 memory: 128M 161 instances: 2 162 disk_quota: 128M 163 routes: 164 - route: %s.%s 165 `, appName, appName, domainName)) 166 manifestPath := filepath.Join(appDir, "manifest.yml") 167 err := ioutil.WriteFile(manifestPath, manifestContents, 0666) 168 Expect(err).ToNot(HaveOccurred()) 169 170 Eventually(helpers.CF("push", appName, "-p", appDir, "-f", manifestPath, "-b", "staticfile_buildpack")).Should(Exit(0)) 171 }) 172 Eventually(helpers.CF("stop", appName)).Should(Exit(0)) 173 }) 174 175 It("displays the app information with instances table", func() { 176 userName, _ := helpers.GetCredentials() 177 session := helpers.CF("start", appName) 178 Eventually(session).Should(Say("Starting app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)) 179 Eventually(session).Should(Say("Name: %s", appName)) 180 Eventually(session).Should(Say("Requested state: started")) 181 Eventually(session).Should(Say("Instances: 2/2")) 182 Eventually(session).Should(Say("Usage: 128M x 2 instances")) 183 Eventually(session).Should(Say("Routes: %s.%s", appName, domainName)) 184 Eventually(session).Should(Say("Last uploaded:")) 185 Eventually(session).Should(Say("Stack: cflinuxfs2")) 186 Eventually(session).Should(Say("Buildpack: staticfile_buildpack")) 187 Eventually(session).Should(Say("Start command: sh boot.sh")) 188 189 Eventually(session).Should(Say("State\\s+Since\\s+CPU\\s+Memory\\s+Disk\\s+Details")) 190 Eventually(session).Should(Say("#0\\s+running\\s+.*\\d+\\.\\d+%.*of 128M.*of 128M")) 191 Eventually(session).Should(Say("#1\\s+running\\s+.*\\d+\\.\\d+%.*of 128M.*of 128M")) 192 Eventually(session).Should(Exit(0)) 193 }) 194 }) 195 196 Context("when the app has *not* been staged", func() { 197 Context("when the app does *not* stage properly", func() { 198 BeforeEach(func() { 199 appName = helpers.PrefixedRandomName("app") 200 domainName = defaultSharedDomain() 201 helpers.WithHelloWorldApp(func(appDir string) { 202 Eventually(helpers.CF("push", appName, "-p", appDir, "--no-start")).Should(Exit(0)) 203 }) 204 }) 205 206 It("displays the app logs and information with instances table", func() { 207 userName, _ := helpers.GetCredentials() 208 session := helpers.CF("start", appName) 209 Eventually(session).Should(Say("Starting app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)) 210 211 Eventually(session).Should(Say("Staging...")) 212 Eventually(session).Should(Say("Error restarting application: NoAppDetectedError")) 213 Eventually(session).Should(Say(`TIP: Buildpacks are detected when the "cf push" is executed from within the directory that contains the app source code.`)) 214 Eventually(session).Should(Exit(1)) 215 }) 216 }) 217 218 Context("when the app stages properly", func() { 219 Context("when the app does *not* start properly", func() { 220 BeforeEach(func() { 221 appName = helpers.PrefixedRandomName("app") 222 domainName = defaultSharedDomain() 223 helpers.WithHelloWorldApp(func(appDir string) { 224 Eventually(helpers.CF("push", appName, "-p", appDir, "--no-start")).Should(Exit(0)) 225 }) 226 }) 227 228 It("displays the app logs and information with instances table", func() { 229 userName, _ := helpers.GetCredentials() 230 session := helpers.CF("start", appName) 231 Eventually(session).Should(Say("Starting app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)) 232 233 Eventually(session).Should(Say("Staging...")) 234 Eventually(session).Should(Say("Error restarting application: Start unsuccessful")) 235 Eventually(session).Should(Say(`TIP: Buildpacks are detected when the "cf push" is executed from within the directory that contains the app source code.`)) 236 Eventually(session).Should(Exit(1)) 237 }) 238 }) 239 240 Context("when the app starts properly", func() { 241 BeforeEach(func() { 242 appName = helpers.PrefixedRandomName("app") 243 domainName = defaultSharedDomain() 244 helpers.WithHelloWorldApp(func(appDir string) { 245 manifestContents := []byte(fmt.Sprintf(` 246 --- 247 applications: 248 - name: %s 249 memory: 128M 250 instances: 2 251 disk_quota: 128M 252 routes: 253 - route: %s.%s 254 `, appName, appName, domainName)) 255 manifestPath := filepath.Join(appDir, "manifest.yml") 256 err := ioutil.WriteFile(manifestPath, manifestContents, 0666) 257 Expect(err).ToNot(HaveOccurred()) 258 259 Eventually(helpers.CF("push", appName, "-p", appDir, "-f", manifestPath, "-b", "staticfile_buildpack", "--no-start")).Should(Exit(0)) 260 }) 261 Eventually(helpers.CF("stop", appName)).Should(Exit(0)) 262 }) 263 264 It("displays the app logs and information with instances table", func() { 265 userName, _ := helpers.GetCredentials() 266 session := helpers.CF("start", appName) 267 Eventually(session).Should(Say("Starting app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)) 268 269 // Display Staging Logs 270 Eventually(session).Should(Say("Staging...")) 271 Eventually(session).Should(Say("Uploading droplet...")) 272 273 Eventually(session).Should(Say("Name: %s", appName)) 274 Eventually(session).Should(Say("Requested state: started")) 275 Eventually(session).Should(Say("Instances: 2/2")) 276 Eventually(session).Should(Say("Usage: 128M x 2 instances")) 277 Eventually(session).Should(Say("Routes: %s.%s", appName, domainName)) 278 Eventually(session).Should(Say("Last uploaded:")) 279 Eventually(session).Should(Say("Stack: cflinuxfs2")) 280 Eventually(session).Should(Say("Buildpack: staticfile_buildpack")) 281 Eventually(session).Should(Say("Start command: sh boot.sh")) 282 283 Eventually(session).Should(Say("State\\s+Since\\s+CPU\\s+Memory\\s+Disk\\s+Details")) 284 Eventually(session).Should(Say("#0\\s+running\\s+.*\\d+\\.\\d+%.*of 128M.*of 128M")) 285 Eventually(session).Should(Say("#1\\s+running\\s+.*\\d+\\.\\d+%.*of 128M.*of 128M")) 286 Eventually(session).Should(Exit(0)) 287 }) 288 }) 289 }) 290 }) 291 }) 292 }) 293 }) 294 })