github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+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  		It("fails with the appropriate errors", func() {
    40  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "start", "app-name")
    41  		})
    42  	})
    43  
    44  	Context("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  			setupCF(orgName, spaceName)
    55  		})
    56  
    57  		AfterEach(func() {
    58  			helpers.QuickDeleteOrg(orgName)
    59  		})
    60  
    61  		Context("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  		Context("when the app does exist", func() {
    73  			var (
    74  				domainName string
    75  				appName    string
    76  			)
    77  
    78  			Context("when the app is started", func() {
    79  				BeforeEach(func() {
    80  					appName = helpers.PrefixedRandomName("app")
    81  					domainName = 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  			Context("when the app is stopped", func() {
    97  				Context("when the app has been staged", func() {
    98  					BeforeEach(func() {
    99  						appName = helpers.PrefixedRandomName("app")
   100  						domainName = 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  					It("displays the app information with instances table", func() {
   122  						userName, _ := helpers.GetCredentials()
   123  						session := helpers.CF("start", appName)
   124  						Eventually(session).Should(Say("Starting app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName))
   125  						Consistently(session).ShouldNot(Say("Staging app and tracing logs\\.\\.\\."))
   126  
   127  						Eventually(session).Should(Say("Waiting for app to start\\.\\.\\."))
   128  
   129  						Eventually(session).Should(Say("name:\\s+%s", appName))
   130  						Eventually(session).Should(Say("requested state:\\s+started"))
   131  						Eventually(session).Should(Say("instances:\\s+2/2"))
   132  						Eventually(session).Should(Say("usage:\\s+128M x 2 instances"))
   133  						Eventually(session).Should(Say("routes:\\s+%s.%s", appName, domainName))
   134  						Eventually(session).Should(Say("last uploaded:"))
   135  						Eventually(session).Should(Say("stack:\\s+cflinuxfs2"))
   136  						Eventually(session).Should(Say("buildpack:\\s+staticfile_buildpack"))
   137  						Eventually(session).Should(Say("start command:"))
   138  
   139  						Eventually(session).Should(Say("state\\s+since\\s+cpu\\s+memory\\s+disk\\s+details"))
   140  						Eventually(session).Should(Say("#0\\s+(running|starting)\\s+.*\\d+\\.\\d+%.*of 128M.*of 128M"))
   141  						Eventually(session).Should(Say("#1\\s+(running|starting)\\s+.*\\d+\\.\\d+%.*of 128M.*of 128M"))
   142  						Eventually(session).Should(Exit(0))
   143  					})
   144  				})
   145  
   146  				Context("when the app has *not* yet been staged", func() {
   147  					Context("when the app does *not* stage properly because the app was not detected by any buildpacks", func() {
   148  						BeforeEach(func() {
   149  							appName = helpers.PrefixedRandomName("app")
   150  							domainName = defaultSharedDomain()
   151  							helpers.WithHelloWorldApp(func(appDir string) {
   152  								err := os.Remove(filepath.Join(appDir, "Staticfile"))
   153  								Expect(err).ToNot(HaveOccurred())
   154  								Eventually(helpers.CF("push", appName, "-p", appDir, "--no-start")).Should(Exit(0))
   155  							})
   156  						})
   157  
   158  						It("fails and displays the staging failure message", func() {
   159  							userName, _ := helpers.GetCredentials()
   160  							session := helpers.CF("start", appName)
   161  							Eventually(session).Should(Say("Starting app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName))
   162  
   163  							// The staticfile_buildback does compile an index.html file. However, it requires a "Staticfile" during buildpack detection.
   164  							Eventually(session.Err).Should(Say("Error staging application: An app was not successfully detected by any available buildpack"))
   165  							Eventually(session.Err).Should(Say(`TIP: Use 'cf buildpacks' to see a list of supported buildpacks.`))
   166  							Eventually(session).Should(Exit(1))
   167  						})
   168  					})
   169  
   170  					Context("when the app stages properly", func() {
   171  						Context("when the app does *not* start properly", func() {
   172  							BeforeEach(func() {
   173  								appName = helpers.PrefixedRandomName("app")
   174  								helpers.WithHelloWorldApp(func(appDir string) {
   175  									Eventually(helpers.CF("push", appName, "-p", appDir, "--no-start", "-b", "staticfile_buildpack", "-c", "gibberish")).Should(Exit(0))
   176  								})
   177  							})
   178  
   179  							It("fails and displays the start failure message", func() {
   180  								userName, _ := helpers.GetCredentials()
   181  								session := helpers.CF("start", appName)
   182  								Eventually(session).Should(Say("Starting app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName))
   183  
   184  								Eventually(session).Should(Say("Staging app and tracing logs\\.\\.\\."))
   185  
   186  								Eventually(session.Err).Should(Say("Start unsuccessful"))
   187  								Eventually(session.Err).Should(Say("TIP: use 'cf logs .* --recent' for more information"))
   188  								Eventually(session).Should(Exit(1))
   189  							})
   190  						})
   191  
   192  						Context("when the app starts properly", func() {
   193  							BeforeEach(func() {
   194  								Eventually(helpers.CF("create-isolation-segment", RealIsolationSegment)).Should(Exit(0))
   195  								Eventually(helpers.CF("enable-org-isolation", orgName, RealIsolationSegment)).Should(Exit(0))
   196  								Eventually(helpers.CF("set-space-isolation-segment", spaceName, RealIsolationSegment)).Should(Exit(0))
   197  								appName = helpers.PrefixedRandomName("app")
   198  								domainName = defaultSharedDomain()
   199  								helpers.WithHelloWorldApp(func(appDir string) {
   200  									manifestContents := []byte(fmt.Sprintf(`
   201  ---
   202  applications:
   203  - name: %s
   204    memory: 128M
   205    instances: 2
   206    disk_quota: 128M
   207    routes:
   208    - route: %s.%s
   209  `, appName, appName, domainName))
   210  									manifestPath := filepath.Join(appDir, "manifest.yml")
   211  									err := ioutil.WriteFile(manifestPath, manifestContents, 0666)
   212  									Expect(err).ToNot(HaveOccurred())
   213  
   214  									Eventually(helpers.CF("push", appName, "-p", appDir, "-f", manifestPath, "-b", "staticfile_buildpack", "--no-start")).Should(Exit(0))
   215  								})
   216  								Eventually(helpers.CF("stop", appName)).Should(Exit(0))
   217  							})
   218  
   219  							It("displays the app logs and information with instances table", func() {
   220  								userName, _ := helpers.GetCredentials()
   221  								session := helpers.CF("start", appName)
   222  								Eventually(session).Should(Say("Starting app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName))
   223  
   224  								// Display Staging Logs
   225  								Eventually(session).Should(Say("Uploading droplet\\.\\.\\."))
   226  								Eventually(session).Should(Say("Waiting for app to start\\.\\.\\."))
   227  
   228  								Eventually(session).Should(Say("name:\\s+%s", appName))
   229  								Eventually(session).Should(Say("requested state:\\s+started"))
   230  								Eventually(session).Should(Say("instances:\\s+2/2"))
   231  								Eventually(session).Should(Say("isolation segment:\\s+%s", RealIsolationSegment))
   232  								Eventually(session).Should(Say("usage:\\s+128M x 2 instances"))
   233  								Eventually(session).Should(Say("routes:\\s+%s.%s", appName, domainName))
   234  								Eventually(session).Should(Say("last uploaded:"))
   235  								Eventually(session).Should(Say("stack:\\s+cflinuxfs2"))
   236  								Eventually(session).Should(Say("buildpack:\\s+staticfile_buildpack"))
   237  								Eventually(session).Should(Say("start command:"))
   238  
   239  								Eventually(session).Should(Say("state\\s+since\\s+cpu\\s+memory\\s+disk\\s+details"))
   240  
   241  								Eventually(session).Should(Say("#0\\s+(running|starting)\\s+.*\\d+\\.\\d+%.*of 128M.*of 128M"))
   242  								Eventually(session).Should(Say("#1\\s+(running|starting)\\s+.*\\d+\\.\\d+%.*of 128M.*of 128M"))
   243  								Eventually(session).Should(Exit(0))
   244  							})
   245  						})
   246  					})
   247  				})
   248  			})
   249  		})
   250  	})
   251  })