github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v7/isolated/start_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
     5  	"code.cloudfoundry.org/cli/integration/helpers"
     6  
     7  	"regexp"
     8  
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  	. "github.com/onsi/gomega/gbytes"
    12  	. "github.com/onsi/gomega/gexec"
    13  )
    14  
    15  const (
    16  	PushCommandName = "push"
    17  )
    18  
    19  var _ = Describe("start command", func() {
    20  	var (
    21  		orgName   string
    22  		spaceName string
    23  		appName   string
    24  	)
    25  
    26  	BeforeEach(func() {
    27  		orgName = helpers.NewOrgName()
    28  		spaceName = helpers.NewSpaceName()
    29  		appName = helpers.PrefixedRandomName("app")
    30  	})
    31  
    32  	Describe("help", func() {
    33  		When("--help flag is set", func() {
    34  			It("appears in cf help -a", func() {
    35  				session := helpers.CF("help", "-a")
    36  				Eventually(session).Should(Exit(0))
    37  				Expect(session).To(HaveCommandInCategoryWithDescription("start", "APPS", "Start an app"))
    38  			})
    39  
    40  			It("Displays command usage to output", func() {
    41  				session := helpers.CF("start", "--help")
    42  
    43  				Eventually(session).Should(Say("NAME:"))
    44  				Eventually(session).Should(Say("start - Start an app"))
    45  				Eventually(session).Should(Say("USAGE:"))
    46  				Eventually(session).Should(Say("cf start APP_NAME"))
    47  				Eventually(session).Should(Say("ALIAS:"))
    48  				Eventually(session).Should(Say("st"))
    49  				Eventually(session).Should(Say("ENVIRONMENT:"))
    50  				Eventually(session).Should(Say(`CF_STAGING_TIMEOUT=15\s+Max wait time for staging, in minutes`))
    51  				Eventually(session).Should(Say(`CF_STARTUP_TIMEOUT=5\s+Max wait time for app instance startup, in minutes`))
    52  				Eventually(session).Should(Say("SEE ALSO:"))
    53  				Eventually(session).Should(Say("apps, logs, restart, run-task, scale, ssh, stop"))
    54  
    55  				Eventually(session).Should(Exit(0))
    56  			})
    57  		})
    58  	})
    59  
    60  	When("the app name is not provided", func() {
    61  		It("tells the user that the app name is required, prints help text, and exits 1", func() {
    62  			session := helpers.CF("start")
    63  
    64  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    65  			Eventually(session).Should(Say("NAME:"))
    66  			Eventually(session).Should(Exit(1))
    67  		})
    68  	})
    69  
    70  	When("the environment is not setup correctly", func() {
    71  		It("fails with the appropriate errors", func() {
    72  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "start", appName)
    73  		})
    74  	})
    75  
    76  	When("the environment is set up correctly", func() {
    77  		BeforeEach(func() {
    78  			helpers.SetupCF(orgName, spaceName)
    79  			Eventually(helpers.CF("create-app", appName)).Should(Exit(0))
    80  		})
    81  
    82  		AfterEach(func() {
    83  			helpers.QuickDeleteOrg(orgName)
    84  		})
    85  
    86  		When("the app exists", func() {
    87  			When("the app does not need to be staged", func() {
    88  				BeforeEach(func() {
    89  					var packageGUID string
    90  
    91  					// TODO: uncomment when map-route works in V7
    92  					// mapRouteSession := helpers.CF("map-route", appName, helpers.DefaultSharedDomain(), "-n", appName)
    93  					// Eventually(mapRouteSession).Should(Exit(0))
    94  
    95  					helpers.WithHelloWorldApp(func(dir string) {
    96  						pkgSession := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, "create-package", appName)
    97  						Eventually(pkgSession).Should(Exit(0))
    98  						regex := regexp.MustCompile(`Package with guid '(.+)' has been created.`)
    99  						matches := regex.FindStringSubmatch(string(pkgSession.Out.Contents()))
   100  						Expect(matches).To(HaveLen(2))
   101  
   102  						packageGUID = matches[1]
   103  					})
   104  
   105  					stageSession := helpers.CF("stage", appName, "--package-guid", packageGUID)
   106  					Eventually(stageSession).Should(Exit(0))
   107  
   108  					regex := regexp.MustCompile(`droplet guid:\s+(.+)`)
   109  					matches := regex.FindStringSubmatch(string(stageSession.Out.Contents()))
   110  					Expect(matches).To(HaveLen(2))
   111  
   112  					dropletGUID := matches[1]
   113  					setDropletSession := helpers.CF("set-droplet", appName, "--droplet-guid", dropletGUID)
   114  					Eventually(setDropletSession).Should(Exit(0))
   115  				})
   116  
   117  				It("starts the app", func() {
   118  					userName, _ := helpers.GetCredentials()
   119  
   120  					session := helpers.CF("start", appName)
   121  					Eventually(session).Should(Say(`Starting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   122  					Eventually(session).Should(Say(`Waiting for app to start\.\.\.`))
   123  					Eventually(session).Should(Say(`name:\s+%s`, appName))
   124  					Eventually(session).Should(Say(`requested state:\s+started`))
   125  					// TODO: uncomment when map-route works in V7
   126  					// Eventually(session).Should(Say(`routes:\s+%s.%s`, appName, helpers.DefaultSharedDomain()))
   127  					Eventually(session).Should(Say(`type:\s+web`))
   128  					Eventually(session).Should(Say(`instances:\s+1/1`))
   129  					Eventually(session).Should(Say(`memory usage:\s+32M`))
   130  					Eventually(session).Should(Say(`\s+state\s+since\s+cpu\s+memory\s+disk\s+details`))
   131  					Eventually(session).Should(Say(`#0\s+(starting|running)\s+\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z`))
   132  
   133  					Eventually(session).Should(Exit(0))
   134  				})
   135  
   136  				When("the app is already started", func() {
   137  					BeforeEach(func() {
   138  						Eventually(helpers.CF("start", appName)).Should(Exit(0))
   139  					})
   140  
   141  					It("displays app already started and exits 0", func() {
   142  						session := helpers.CF("start", appName)
   143  
   144  						Eventually(session).Should(Say(`App '%s' is already started\.`, appName))
   145  						Eventually(session).Should(Say("OK"))
   146  
   147  						Eventually(session).Should(Exit(0))
   148  					})
   149  				})
   150  			})
   151  
   152  			When("the app needs to be staged", func() {
   153  				var packageGUID = ""
   154  				BeforeEach(func() {
   155  					helpers.WithHelloWorldApp(func(dir string) {
   156  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName)
   157  						Eventually(session).Should(Say(`\s+name:\s+%s`, appName))
   158  						Eventually(session).Should(Say(`requested state:\s+started`))
   159  						Eventually(session).Should(Exit(0))
   160  					})
   161  
   162  					session := helpers.CF("stop", appName)
   163  					Eventually(session).Should(Say("OK"))
   164  
   165  					helpers.WithBananaPantsApp(func(dir string) {
   166  						pkgSession := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, "create-package", appName)
   167  						Eventually(pkgSession).Should(Exit(0))
   168  						regex := regexp.MustCompile(`Package with guid '(.+)' has been created.`)
   169  						matches := regex.FindStringSubmatch(string(pkgSession.Out.Contents()))
   170  						Expect(matches).To(HaveLen(2))
   171  
   172  						packageGUID = matches[1]
   173  					})
   174  				})
   175  
   176  				It("stages and starts the app", func() {
   177  					session := helpers.CF("start", appName)
   178  
   179  					Eventually(session).Should(Say(`Staging app and tracing logs`))
   180  					helpers.ConfirmStagingLogs(session)
   181  
   182  					Eventually(session).Should(Say(`Waiting for app to start\.\.\.`))
   183  					Eventually(session).Should(Say(`name:\s+%s`, appName))
   184  					Eventually(session).Should(Say(`requested state:\s+started`))
   185  					Eventually(session).Should(Say(`type:\s+web`))
   186  					Eventually(session).Should(Say(`instances:\s+1/1`))
   187  					Eventually(session).Should(Say(`memory usage:\s+32M`))
   188  					Eventually(session).Should(Say(`\s+state\s+since\s+cpu\s+memory\s+disk\s+details`))
   189  					Eventually(session).Should(Say(`#0\s+(starting|running)\s+\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z`))
   190  
   191  					Eventually(session).Should(Exit(0))
   192  					Expect(session.Err).ToNot(Say(`timeout connecting to log server, no log will be shown`))
   193  
   194  					Expect(helpers.GetPackageFirstDroplet(packageGUID)).To(Equal(helpers.GetAppDroplet(helpers.AppGUID(appName))))
   195  				})
   196  			})
   197  
   198  			When("the app cannot be started or staged", func() {
   199  				It("gives an error", func() {
   200  					session := helpers.CF("start", appName)
   201  
   202  					Eventually(session.Err).Should(Say(`App can not start with out a package to stage or a droplet to run.`))
   203  					Eventually(session).Should(Say("FAILED"))
   204  
   205  					Eventually(session).Should(Exit(1))
   206  				})
   207  			})
   208  		})
   209  
   210  		When("the app does not exist", func() {
   211  			It("displays app not found and exits 1", func() {
   212  				invalidAppName := "invalid-app-name"
   213  				session := helpers.CF("start", invalidAppName)
   214  
   215  				Eventually(session.Err).Should(Say(`App '%s' not found\.`, invalidAppName))
   216  				Eventually(session).Should(Say("FAILED"))
   217  
   218  				Eventually(session).Should(Exit(1))
   219  			})
   220  		})
   221  	})
   222  })