github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/v7/isolated/restart_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  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/gomega"
     8  	. "github.com/onsi/gomega/gbytes"
     9  	. "github.com/onsi/gomega/gexec"
    10  )
    11  
    12  var _ = Describe("restart command", func() {
    13  	var (
    14  		orgName   string
    15  		spaceName string
    16  		appName   string
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		orgName = helpers.NewOrgName()
    21  		spaceName = helpers.NewSpaceName()
    22  		appName = helpers.PrefixedRandomName("app")
    23  	})
    24  
    25  	Describe("help", func() {
    26  		When("--help flag is set", func() {
    27  			It("appears in cf help -a", func() {
    28  				session := helpers.CF("help", "-a")
    29  				Eventually(session).Should(Exit(0))
    30  				Expect(session).To(HaveCommandInCategoryWithDescription("restart", "APPS", "Stop all instances of the app, then start them again. This causes downtime."))
    31  			})
    32  
    33  			It("displays command usage to output", func() {
    34  				session := helpers.CF("restart", "--help")
    35  
    36  				Eventually(session).Should(Say("NAME:"))
    37  				Eventually(session).Should(Say(`restart - Stop all instances of the app, then start them again\. This causes downtime\.`))
    38  				Eventually(session).Should(Say("USAGE:"))
    39  				Eventually(session).Should(Say("cf restart APP_NAME"))
    40  				Eventually(session).Should(Say("ALIAS:"))
    41  				Eventually(session).Should(Say("rs"))
    42  				Eventually(session).Should(Say("ENVIRONMENT:"))
    43  				Eventually(session).Should(Say(`CF_STAGING_TIMEOUT=15\s+Max wait time for staging, in minutes`))
    44  				Eventually(session).Should(Say(`CF_STARTUP_TIMEOUT=5\s+Max wait time for app instance startup, in minutes`))
    45  				Eventually(session).Should(Say("SEE ALSO:"))
    46  				Eventually(session).Should(Say("restage, restart-app-instance"))
    47  
    48  				Eventually(session).Should(Exit(0))
    49  			})
    50  		})
    51  	})
    52  
    53  	When("the app name is not provided", func() {
    54  		It("tells the user that the app name is required, prints help text, and exits 1", func() {
    55  			session := helpers.CF("restart")
    56  
    57  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    58  			Eventually(session).Should(Say("NAME:"))
    59  			Eventually(session).Should(Exit(1))
    60  		})
    61  	})
    62  
    63  	When("the environment is not setup correctly", func() {
    64  		It("fails with the appropriate errors", func() {
    65  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "restart", appName)
    66  		})
    67  	})
    68  
    69  	When("the environment is set up correctly", func() {
    70  		var (
    71  			userName string
    72  		)
    73  		BeforeEach(func() {
    74  			helpers.SetupCF(orgName, spaceName)
    75  			userName, _ = helpers.GetCredentials()
    76  		})
    77  
    78  		AfterEach(func() {
    79  			helpers.QuickDeleteOrg(orgName)
    80  		})
    81  
    82  		When("the app exists", func() {
    83  			When("strategy rolling is given", func() {
    84  				BeforeEach(func() {
    85  					helpers.WithHelloWorldApp(func(appDir string) {
    86  						Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName)).Should(Exit(0))
    87  					})
    88  				})
    89  				It("creates a deploy", func() {
    90  					session := helpers.CF("restart", appName, "--strategy=rolling")
    91  					Eventually(session).Should(Say(`Restarting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
    92  					Eventually(session).Should(Say(`Creating deployment for app %s\.\.\.`, appName))
    93  					Eventually(session).Should(Say(`Waiting for app to deploy\.\.\.`))
    94  					Eventually(session).Should(Say(`name:\s+%s`, appName))
    95  					Eventually(session).Should(Say(`requested state:\s+started`))
    96  					Eventually(session).Should(Say(`routes:\s+%s.%s`, appName, helpers.DefaultSharedDomain()))
    97  					Eventually(session).Should(Say(`type:\s+web`))
    98  					Eventually(session).Should(Say(`instances:\s+1/1`))
    99  					Eventually(session).Should(Say(`memory usage:\s+\d+(M|G)`))
   100  					Eventually(session).Should(Say(`\s+state\s+since\s+cpu\s+memory\s+disk\s+details`))
   101  					Eventually(session).Should(Say(`#0\s+(starting|running)\s+\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z`))
   102  
   103  				})
   104  			})
   105  
   106  			When("the app is running", func() {
   107  				BeforeEach(func() {
   108  					helpers.WithHelloWorldApp(func(appDir string) {
   109  						Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName)).Should(Exit(0))
   110  					})
   111  				})
   112  
   113  				It("stops then restarts the app", func() {
   114  
   115  					session := helpers.CF("restart", appName)
   116  					Eventually(session).Should(Say(`Restarting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   117  					Eventually(session).Should(Say(`Stopping app\.\.\.`))
   118  					Eventually(session).Should(Say(`Waiting for app to start\.\.\.`))
   119  					Eventually(session).Should(Say(`name:\s+%s`, appName))
   120  					Eventually(session).Should(Say(`requested state:\s+started`))
   121  					Eventually(session).Should(Say(`routes:\s+%s.%s`, appName, helpers.DefaultSharedDomain()))
   122  					Eventually(session).Should(Say(`type:\s+web`))
   123  					Eventually(session).Should(Say(`instances:\s+1/1`))
   124  					Eventually(session).Should(Say(`memory usage:\s+\d+(M|G)`))
   125  					Eventually(session).Should(Say(`\s+state\s+since\s+cpu\s+memory\s+disk\s+details`))
   126  					Eventually(session).Should(Say(`#0\s+(starting|running)\s+\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z`))
   127  
   128  					Eventually(session).Should(Exit(0))
   129  					Expect(session.Err).ToNot(Say(`timeout connecting to log server, no log will be shown`))
   130  				})
   131  			})
   132  
   133  			When("the app is stopped", func() {
   134  				When("the app is already staged", func() {
   135  					BeforeEach(func() {
   136  						helpers.WithHelloWorldApp(func(appDir string) {
   137  							Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName)).Should(Exit(0))
   138  						})
   139  						Eventually(helpers.CF("stop", appName)).Should(Exit(0))
   140  					})
   141  
   142  					It("starts the app", func() {
   143  
   144  						session := helpers.CF("restart", appName)
   145  						Eventually(session).Should(Say(`Restarting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   146  						Eventually(session).Should(Say(`Waiting for app to start\.\.\.`))
   147  						Eventually(session).Should(Say(`name:\s+%s`, appName))
   148  						Eventually(session).Should(Say(`requested state:\s+started`))
   149  						Eventually(session).Should(Say(`routes:\s+%s.%s`, appName, helpers.DefaultSharedDomain()))
   150  						Eventually(session).Should(Say(`type:\s+web`))
   151  						Eventually(session).Should(Say(`instances:\s+1/1`))
   152  						Eventually(session).Should(Say(`memory usage:\s+\d+(M|G)`))
   153  						Eventually(session).Should(Say(`\s+state\s+since\s+cpu\s+memory\s+disk\s+details`))
   154  						Eventually(session).Should(Say(`#0\s+(starting|running)\s+\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z`))
   155  
   156  						Expect(session.Out.Contents()).NotTo(ContainSubstring("Stopping app..."))
   157  
   158  						Eventually(session).Should(Exit(0))
   159  					})
   160  				})
   161  
   162  				When("the app is *not* staged", func() {
   163  					BeforeEach(func() {
   164  						helpers.WithHelloWorldApp(func(appDir string) {
   165  							Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName, "--no-start")).Should(Exit(0))
   166  						})
   167  					})
   168  
   169  					It("complains about not having a droplet", func() {
   170  
   171  						session := helpers.CF("restart", appName)
   172  						Eventually(session).Should(Say(`Restarting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   173  						Eventually(session.Err).Should(Say(`App can not start with out a package to stage or a droplet to run\.`))
   174  						Eventually(session).Should(Say("FAILED"))
   175  						Eventually(session).Should(Exit(1))
   176  					})
   177  				})
   178  			})
   179  		})
   180  
   181  		When("the app does not exist", func() {
   182  			It("displays app not found and exits 1", func() {
   183  				invalidAppName := helpers.PrefixedRandomName("invalid-app")
   184  				session := helpers.CF("restart", invalidAppName)
   185  
   186  				Eventually(session.Err).Should(Say(`App '%s' not found\.`, invalidAppName))
   187  				Eventually(session).Should(Say("FAILED"))
   188  
   189  				Eventually(session).Should(Exit(1))
   190  			})
   191  		})
   192  	})
   193  })