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