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