github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/shared/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/api/cloudcontroller/ccversion" 10 "code.cloudfoundry.org/cli/integration/helpers" 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 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 When("the environment is not setup correctly", func() { 39 It("fails with the appropriate errors", func() { 40 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "start", "app-name") 41 }) 42 }) 43 44 When("the environment is set up correctly", func() { 45 var ( 46 orgName string 47 spaceName string 48 ) 49 50 BeforeEach(func() { 51 orgName = helpers.NewOrgName() 52 spaceName = helpers.NewSpaceName() 53 54 helpers.SetupCF(orgName, spaceName) 55 }) 56 57 AfterEach(func() { 58 helpers.QuickDeleteOrg(orgName) 59 }) 60 61 When("the app does not exist", func() { 62 It("tells the user that the start is not found and exits 1", func() { 63 appName := helpers.PrefixedRandomName("app") 64 session := helpers.CF("start", appName) 65 66 Eventually(session).Should(Say("FAILED")) 67 Eventually(session.Err).Should(Say("App %s not found", appName)) 68 Eventually(session).Should(Exit(1)) 69 }) 70 }) 71 72 When("the app does exist", func() { 73 var ( 74 domainName string 75 appName string 76 ) 77 78 When("the app is started", func() { 79 BeforeEach(func() { 80 appName = helpers.PrefixedRandomName("app") 81 domainName = helpers.DefaultSharedDomain() 82 helpers.WithHelloWorldApp(func(appDir string) { 83 Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0)) 84 }) 85 }) 86 87 It("only displays the app already started message", func() { 88 userName, _ := helpers.GetCredentials() 89 session := helpers.CF("start", appName) 90 Eventually(session).Should(Say("Starting app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)) 91 Eventually(session).Should(Say("App %s is already started", appName)) 92 Eventually(session).Should(Exit(0)) 93 }) 94 }) 95 96 When("the app is stopped", func() { 97 When("the app has been staged", func() { 98 BeforeEach(func() { 99 appName = helpers.PrefixedRandomName("app") 100 domainName = helpers.DefaultSharedDomain() 101 helpers.WithHelloWorldApp(func(appDir string) { 102 manifestContents := []byte(fmt.Sprintf(` 103 --- 104 applications: 105 - name: %s 106 memory: 128M 107 instances: 2 108 disk_quota: 128M 109 routes: 110 - route: %s.%s 111 `, appName, appName, domainName)) 112 manifestPath := filepath.Join(appDir, "manifest.yml") 113 err := ioutil.WriteFile(manifestPath, manifestContents, 0666) 114 Expect(err).ToNot(HaveOccurred()) 115 116 Eventually(helpers.CF("push", appName, "-p", appDir, "-f", manifestPath, "-b", "staticfile_buildpack")).Should(Exit(0)) 117 }) 118 Eventually(helpers.CF("stop", appName)).Should(Exit(0)) 119 }) 120 121 Describe("version dependent display", func() { 122 When("CC API >= 3.27.0", func() { 123 BeforeEach(func() { 124 helpers.SkipIfVersionLessThan(ccversion.MinVersionApplicationFlowV3) 125 }) 126 127 It("uses the multiprocess display", func() { 128 userName, _ := helpers.GetCredentials() 129 130 session := helpers.CF("start", appName) 131 132 Eventually(session).Should(Say(`Starting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 133 134 Eventually(session).Should(Say(`name:\s+%s`, appName)) 135 Eventually(session).Should(Say(`requested state:\s+started`)) 136 Eventually(session).Should(Say(`routes:\s+%s\.%s`, appName, domainName)) 137 Eventually(session).Should(Say(`last uploaded:\s+\w{3} \d{1,2} \w{3} \d{2}:\d{2}:\d{2} \w{3} \d{4}`)) 138 Eventually(session).Should(Say(`stack:\s+cflinuxfs2`)) 139 Eventually(session).Should(Say(`buildpacks:\s+staticfile`)) 140 Eventually(session).Should(Say(`type:\s+web`)) 141 Eventually(session).Should(Say(`instances:\s+\d/2`)) 142 Eventually(session).Should(Say(`memory usage:\s+128M`)) 143 Eventually(session).Should(Say(`\s+state\s+since\s+cpu\s+memory\s+disk`)) 144 Eventually(session).Should(Say(`#0\s+(starting|running)\s+\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z`)) 145 146 Eventually(session).Should(Exit(0)) 147 }) 148 149 }) 150 151 When("CC API < 3.27.0", func() { 152 BeforeEach(func() { 153 helpers.SkipIfVersionAtLeast(ccversion.MinVersionApplicationFlowV3) 154 }) 155 156 It("displays the app logs and information with instances table", func() { 157 userName, _ := helpers.GetCredentials() 158 session := helpers.CF("start", appName) 159 Eventually(session).Should(Say(`Starting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 160 Consistently(session).ShouldNot(Say(`Staging app and tracing logs\.\.\.`)) 161 162 Eventually(session).Should(Say(`Waiting for app to start\.\.\.`)) 163 164 Eventually(session).Should(Say(`name:\s+%s`, appName)) 165 Eventually(session).Should(Say(`requested state:\s+started`)) 166 Eventually(session).Should(Say(`instances:\s+2/2`)) 167 Eventually(session).Should(Say(`usage:\s+128M x 2 instances`)) 168 Eventually(session).Should(Say(`routes:\s+%s.%s`, appName, domainName)) 169 Eventually(session).Should(Say("last uploaded:")) 170 Eventually(session).Should(Say(`stack:\s+cflinuxfs2`)) 171 Eventually(session).Should(Say(`buildpack:\s+staticfile_buildpack`)) 172 Eventually(session).Should(Say("start command:")) 173 174 Eventually(session).Should(Say(`state\s+since\s+cpu\s+memory\s+disk\s+details`)) 175 Eventually(session).Should(Say(`#0\s+(running|starting)\s+.*\d+\.\d+%.*of 128M.*of 128M`)) 176 Eventually(session).Should(Say(`#1\s+(running|starting)\s+.*\d+\.\d+%.*of 128M.*of 128M`)) 177 Eventually(session).Should(Exit(0)) 178 }) 179 }) 180 }) 181 }) 182 183 When("the app has *not* yet been staged", func() { 184 When("the app does *not* stage properly because the app was not detected by any buildpacks", func() { 185 BeforeEach(func() { 186 appName = helpers.PrefixedRandomName("app") 187 domainName = helpers.DefaultSharedDomain() 188 helpers.WithHelloWorldApp(func(appDir string) { 189 err := os.Remove(filepath.Join(appDir, "Staticfile")) 190 Expect(err).ToNot(HaveOccurred()) 191 Eventually(helpers.CF("push", appName, "-p", appDir, "--no-start")).Should(Exit(0)) 192 }) 193 }) 194 195 It("fails and displays the staging failure message", func() { 196 userName, _ := helpers.GetCredentials() 197 session := helpers.CF("start", appName) 198 Eventually(session).Should(Say(`Starting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 199 200 // The staticfile_buildback does compile an index.html file. However, it requires a "Staticfile" during buildpack detection. 201 Eventually(session.Err).Should(Say("Error staging application: An app was not successfully detected by any available buildpack")) 202 Eventually(session.Err).Should(Say(`TIP: Use 'cf buildpacks' to see a list of supported buildpacks.`)) 203 Eventually(session).Should(Exit(1)) 204 }) 205 }) 206 207 When("the app stages properly", func() { 208 When("the app does *not* start properly", func() { 209 BeforeEach(func() { 210 appName = helpers.PrefixedRandomName("app") 211 helpers.WithHelloWorldApp(func(appDir string) { 212 Eventually(helpers.CF("push", appName, "-p", appDir, "--no-start", "-b", "staticfile_buildpack", "-c", "gibberish")).Should(Exit(0)) 213 }) 214 }) 215 216 It("fails and displays the start failure message", func() { 217 userName, _ := helpers.GetCredentials() 218 session := helpers.CF("start", appName) 219 Eventually(session).Should(Say(`Starting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 220 221 Eventually(session).Should(Say(`Staging app and tracing logs\.\.\.`)) 222 223 Eventually(session.Err).Should(Say("Start unsuccessful")) 224 Eventually(session.Err).Should(Say("TIP: use 'cf logs .* --recent' for more information")) 225 Eventually(session).Should(Exit(1)) 226 }) 227 }) 228 229 When("the app starts properly", func() { 230 BeforeEach(func() { 231 appName = helpers.PrefixedRandomName("app") 232 domainName = helpers.DefaultSharedDomain() 233 helpers.WithHelloWorldApp(func(appDir string) { 234 manifestContents := []byte(fmt.Sprintf(` 235 --- 236 applications: 237 - name: %s 238 memory: 128M 239 instances: 2 240 disk_quota: 128M 241 routes: 242 - route: %s.%s 243 `, appName, appName, domainName)) 244 manifestPath := filepath.Join(appDir, "manifest.yml") 245 err := ioutil.WriteFile(manifestPath, manifestContents, 0666) 246 Expect(err).ToNot(HaveOccurred()) 247 248 Eventually(helpers.CF("push", appName, "-p", appDir, "-f", manifestPath, "-b", "staticfile_buildpack", "--no-start")).Should(Exit(0)) 249 }) 250 }) 251 252 Describe("version dependent display", func() { 253 When("CC API >= 3.27.0", func() { 254 BeforeEach(func() { 255 helpers.SkipIfVersionLessThan(ccversion.MinVersionApplicationFlowV3) 256 }) 257 258 It("uses the multiprocess display", func() { 259 userName, _ := helpers.GetCredentials() 260 261 session := helpers.CF("start", appName) 262 263 Eventually(session).Should(Say(`Starting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 264 265 Eventually(session).Should(Say(`name:\s+%s`, appName)) 266 Eventually(session).Should(Say(`requested state:\s+started`)) 267 Eventually(session).Should(Say(`routes:\s+%s\.%s`, appName, domainName)) 268 Eventually(session).Should(Say(`last uploaded:\s+\w{3} \d{1,2} \w{3} \d{2}:\d{2}:\d{2} \w{3} \d{4}`)) 269 Eventually(session).Should(Say(`stack:\s+cflinuxfs2`)) 270 Eventually(session).Should(Say(`buildpacks:\s+staticfile`)) 271 Eventually(session).Should(Say(`type:\s+web`)) 272 Eventually(session).Should(Say(`instances:\s+\d/2`)) 273 Eventually(session).Should(Say(`memory usage:\s+128M`)) 274 Eventually(session).Should(Say(`\s+state\s+since\s+cpu\s+memory\s+disk`)) 275 Eventually(session).Should(Say(`#0\s+(starting|running)\s+\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z`)) 276 277 Eventually(session).Should(Exit(0)) 278 }) 279 280 }) 281 282 When("CC API < 3.27.0", func() { 283 BeforeEach(func() { 284 helpers.SkipIfVersionAtLeast(ccversion.MinVersionApplicationFlowV3) 285 }) 286 287 It("displays the app logs and information with instances table", func() { 288 userName, _ := helpers.GetCredentials() 289 session := helpers.CF("start", appName) 290 Eventually(session).Should(Say(`Starting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName)) 291 292 helpers.ConfirmStagingLogs(session) 293 294 Eventually(session).Should(Say(`name:\s+%s`, appName)) 295 Eventually(session).Should(Say(`requested state:\s+started`)) 296 Eventually(session).Should(Say(`instances:\s+2/2`)) 297 Eventually(session).Should(Say(`usage:\s+128M x 2 instances`)) 298 Eventually(session).Should(Say(`routes:\s+%s.%s`, appName, domainName)) 299 Eventually(session).Should(Say("last uploaded:")) 300 Eventually(session).Should(Say(`stack:\s+cflinuxfs2`)) 301 Eventually(session).Should(Say(`buildpack:\s+staticfile_buildpack`)) 302 Eventually(session).Should(Say("start command:")) 303 304 Eventually(session).Should(Say(`state\s+since\s+cpu\s+memory\s+disk\s+details`)) 305 306 Eventually(session).Should(Say(`#0\s+(running|starting)\s+.*\d+\.\d+%.*of 128M.*of 128M`)) 307 Eventually(session).Should(Say(`#1\s+(running|starting)\s+.*\d+\.\d+%.*of 128M.*of 128M`)) 308 Eventually(session).Should(Exit(0)) 309 }) 310 }) 311 }) 312 313 When("using isolation segments", func() { 314 BeforeEach(func() { 315 helpers.SkipIfVersionLessThan(ccversion.MinVersionIsolationSegmentV3) 316 Eventually(helpers.CF("create-isolation-segment", RealIsolationSegment)).Should(Exit(0)) 317 Eventually(helpers.CF("enable-org-isolation", orgName, RealIsolationSegment)).Should(Exit(0)) 318 Eventually(helpers.CF("set-space-isolation-segment", spaceName, RealIsolationSegment)).Should(Exit(0)) 319 appName = helpers.PrefixedRandomName("app") 320 helpers.WithHelloWorldApp(func(appDir string) { 321 Eventually(helpers.CF("push", appName, "-p", appDir, "--no-start")).Should(Exit(0)) 322 }) 323 }) 324 325 It("displays the app logs and information with instances table", func() { 326 session := helpers.CF("start", appName) 327 328 Eventually(session).Should(Say(`isolation segment:\s+%s`, RealIsolationSegment)) 329 }) 330 }) 331 }) 332 }) 333 }) 334 }) 335 }) 336 }) 337 })