github.com/wanddynosios/cli@v7.1.0+incompatible/integration/v6/isolated/restart_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("restart 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("restart", "--help")
    21  
    22  				Eventually(session).Should(Say("NAME:"))
    23  				Eventually(session).Should(Say("restart - Stop all instances of the app, then start them again. This causes downtime."))
    24  				Eventually(session).Should(Say("USAGE:"))
    25  				Eventually(session).Should(Say("cf restart APP_NAME"))
    26  				Eventually(session).Should(Say("ALIAS:"))
    27  				Eventually(session).Should(Say("rs"))
    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("restage, restart-app-instance"))
    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, "restart", "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("restart", 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  			BeforeEach(func() {
    79  				appName = helpers.PrefixedRandomName("app")
    80  				domainName = helpers.DefaultSharedDomain()
    81  			})
    82  
    83  			When("the app is started", func() {
    84  				BeforeEach(func() {
    85  					helpers.WithHelloWorldApp(func(appDir string) {
    86  						Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0))
    87  					})
    88  				})
    89  
    90  				It("stops the app and starts it again", func() {
    91  					userName, _ := helpers.GetCredentials()
    92  					session := helpers.CF("restart", appName)
    93  					Eventually(session).Should(Say(`Restarting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
    94  					Eventually(session).Should(Say(`Stopping app\.\.\.`))
    95  					Consistently(session).ShouldNot(Say(`Staging app and tracing logs\.\.\.`))
    96  					Eventually(session).Should(Say(`Waiting for app to start\.\.\.`))
    97  					Eventually(session).Should(Exit(0))
    98  				})
    99  			})
   100  
   101  			When("the app is stopped", func() {
   102  				When("the app has been staged", func() {
   103  					BeforeEach(func() {
   104  						helpers.WithHelloWorldApp(func(appDir string) {
   105  							manifestContents := []byte(fmt.Sprintf(`
   106  ---
   107  applications:
   108  - name: %s
   109    memory: 128M
   110    instances: 2
   111    disk_quota: 128M
   112    routes:
   113    - route: %s.%s
   114  `, appName, appName, domainName))
   115  							manifestPath := filepath.Join(appDir, "manifest.yml")
   116  							err := ioutil.WriteFile(manifestPath, manifestContents, 0666)
   117  							Expect(err).ToNot(HaveOccurred())
   118  
   119  							Eventually(helpers.CF("push", appName, "-p", appDir, "-f", manifestPath, "-b", "staticfile_buildpack")).Should(Exit(0))
   120  						})
   121  						Eventually(helpers.CF("stop", appName)).Should(Exit(0))
   122  					})
   123  
   124  					Describe("multiprocess display", func() {
   125  						It("uses the multiprocess display", func() {
   126  							userName, _ := helpers.GetCredentials()
   127  
   128  							session := helpers.CF("start", appName)
   129  
   130  							Eventually(session).Should(Say(`Starting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   131  
   132  							Eventually(session).Should(Say(`name:\s+%s`, appName))
   133  							Eventually(session).Should(Say(`requested state:\s+started`))
   134  							Eventually(session).Should(Say(`routes:\s+%s\.%s`, appName, domainName))
   135  							Eventually(session).Should(Say(`last uploaded:\s+%s`, helpers.ReadableDateTimeRegex))
   136  							Eventually(session).Should(Say(`stack:\s+cflinuxfs`))
   137  							Eventually(session).Should(Say(`buildpacks:\s+staticfile`))
   138  							Eventually(session).Should(Say(`type:\s+web`))
   139  							Eventually(session).Should(Say(`instances:\s+\d/2`))
   140  							Eventually(session).Should(Say(`memory usage:\s+128M`))
   141  							Eventually(session).Should(Say(`\s+state\s+since\s+cpu\s+memory\s+disk`))
   142  							Eventually(session).Should(Say(`#0\s+(starting|running)\s+\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z`))
   143  
   144  							Eventually(session).Should(Exit(0))
   145  						})
   146  					})
   147  				})
   148  
   149  				When("the app does *not* stage properly because the app was not detected by any buildpacks", func() {
   150  					BeforeEach(func() {
   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("restart", appName)
   161  						Eventually(session).Should(Say(`Restarting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   162  						Eventually(session).Should(Say(`Staging app and tracing logs\.\.\.`))
   163  
   164  						// The staticfile_buildback does compile an index.html file. However, it requires a "Staticfile" during buildpack detection.
   165  						Eventually(session.Err).Should(Say("Error staging application: An app was not successfully detected by any available buildpack"))
   166  						Eventually(session.Err).Should(Say(`TIP: Use 'cf buildpacks' to see a list of supported buildpacks.`))
   167  						Eventually(session).Should(Exit(1))
   168  					})
   169  				})
   170  
   171  				When("the app stages properly", func() {
   172  					When("the app does *not* start properly", func() {
   173  						BeforeEach(func() {
   174  							appName = helpers.PrefixedRandomName("app")
   175  							helpers.WithHelloWorldApp(func(appDir string) {
   176  								Eventually(helpers.CF("push", appName, "-p", appDir, "--no-start", "-b", "staticfile_buildpack", "-c", "gibberish")).Should(Exit(0))
   177  							})
   178  						})
   179  
   180  						It("fails and displays the start failure message", func() {
   181  							userName, _ := helpers.GetCredentials()
   182  							session := helpers.CF("restart", appName)
   183  							Eventually(session).Should(Say(`Restarting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   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  							helpers.WithHelloWorldApp(func(appDir string) {
   194  								manifestContents := []byte(fmt.Sprintf(`
   195  ---
   196  applications:
   197  - name: %s
   198    memory: 128M
   199    instances: 2
   200    disk_quota: 128M
   201    routes:
   202    - route: %s.%s
   203  `, appName, appName, domainName))
   204  								manifestPath := filepath.Join(appDir, "manifest.yml")
   205  								err := ioutil.WriteFile(manifestPath, manifestContents, 0666)
   206  								Expect(err).ToNot(HaveOccurred())
   207  
   208  								Eventually(helpers.CF("push", appName, "-p", appDir, "-f", manifestPath, "-b", "staticfile_buildpack", "--no-start")).Should(Exit(0))
   209  							})
   210  							Eventually(helpers.CF("stop", appName)).Should(Exit(0))
   211  						})
   212  
   213  						It("displays the app logs and information with instances table", func() {
   214  							userName, _ := helpers.GetCredentials()
   215  							session := helpers.CF("restart", appName)
   216  							Eventually(session).Should(Say(`Restarting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   217  							Consistently(session).ShouldNot(Say(`Stopping app\.\.\.`))
   218  
   219  							helpers.ConfirmStagingLogs(session)
   220  
   221  							Eventually(session).Should(Say(`name:\s+%s`, appName))
   222  							Eventually(session).Should(Say(`memory usage:\s+128M`))
   223  							Eventually(session).Should(Exit(0))
   224  						})
   225  					})
   226  
   227  					When("isolation segments are available", func() {
   228  						BeforeEach(func() {
   229  							Eventually(helpers.CF("create-isolation-segment", RealIsolationSegment)).Should(Exit(0))
   230  							Eventually(helpers.CF("enable-org-isolation", orgName, RealIsolationSegment)).Should(Exit(0))
   231  							Eventually(helpers.CF("set-space-isolation-segment", spaceName, RealIsolationSegment)).Should(Exit(0))
   232  
   233  							helpers.WithHelloWorldApp(func(appDir string) {
   234  								Eventually(helpers.CF("push", appName, "-p", appDir, "--no-start")).Should(Exit(0))
   235  							})
   236  						})
   237  
   238  						It("displays the isolation segment information", func() {
   239  							session := helpers.CF("restart", appName)
   240  
   241  							Eventually(session).Should(Say(`isolation segment:\s+%s`, RealIsolationSegment))
   242  							Eventually(session).Should(Exit(0))
   243  						})
   244  					})
   245  				})
   246  			})
   247  		})
   248  	})
   249  })