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