github.com/wanddynosios/cli@v7.1.0+incompatible/integration/v6/experimental/v3_restart_command_test.go (about)

     1  package experimental
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/integration/helpers"
     5  	. "github.com/onsi/ginkgo"
     6  	. "github.com/onsi/gomega"
     7  	. "github.com/onsi/gomega/gbytes"
     8  	. "github.com/onsi/gomega/gexec"
     9  )
    10  
    11  var _ = Describe("v3-restart command", func() {
    12  	var (
    13  		orgName   string
    14  		spaceName string
    15  		appName   string
    16  	)
    17  
    18  	BeforeEach(func() {
    19  		orgName = helpers.NewOrgName()
    20  		spaceName = helpers.NewSpaceName()
    21  		appName = helpers.PrefixedRandomName("app")
    22  	})
    23  
    24  	Describe("help", func() {
    25  		When("--help flag is set", func() {
    26  			It("displays command usage to output", func() {
    27  				session := helpers.CF("v3-restart", "--help")
    28  
    29  				Eventually(session).Should(Say("NAME:"))
    30  				Eventually(session).Should(Say(`v3-restart - Stop all instances of the app, then start them again\. This causes downtime\.`))
    31  				Eventually(session).Should(Say("USAGE:"))
    32  				Eventually(session).Should(Say("cf v3-restart APP_NAME"))
    33  				Eventually(session).Should(Say("ENVIRONMENT:"))
    34  				Eventually(session).Should(Say(`CF_STARTUP_TIMEOUT=5\s+Max wait time for app instance startup, in minutes`))
    35  
    36  				Eventually(session).Should(Exit(0))
    37  			})
    38  		})
    39  	})
    40  
    41  	When("the app name is not provided", func() {
    42  		It("tells the user that the app name is required, prints help text, and exits 1", func() {
    43  			session := helpers.CF("v3-restart")
    44  
    45  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    46  			Eventually(session).Should(Say("NAME:"))
    47  			Eventually(session).Should(Exit(1))
    48  		})
    49  	})
    50  
    51  	It("displays the experimental warning", func() {
    52  		session := helpers.CF("v3-restart", appName)
    53  		Eventually(session.Err).Should(Say("This command is in EXPERIMENTAL stage and may change without notice"))
    54  		Eventually(session).Should(Exit())
    55  	})
    56  
    57  	When("the environment is not setup correctly", func() {
    58  		It("fails with the appropriate errors", func() {
    59  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "v3-restart", appName)
    60  		})
    61  	})
    62  
    63  	When("the environment is set up correctly", func() {
    64  		BeforeEach(func() {
    65  			helpers.SetupCF(orgName, spaceName)
    66  		})
    67  
    68  		AfterEach(func() {
    69  			helpers.QuickDeleteOrg(orgName)
    70  		})
    71  
    72  		When("the app exists", func() {
    73  			BeforeEach(func() {
    74  				helpers.WithHelloWorldApp(func(appDir string) {
    75  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)).Should(Exit(0))
    76  				})
    77  			})
    78  
    79  			When("the app is running", func() {
    80  				It("stops then restarts the app", func() {
    81  					userName, _ := helpers.GetCredentials()
    82  
    83  					session := helpers.CF("v3-restart", appName)
    84  					Eventually(session).Should(Say(`Stopping app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
    85  					Eventually(session).Should(Say("OK"))
    86  					Eventually(session).Should(Say(`Starting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
    87  					Eventually(session).Should(Say("OK"))
    88  
    89  					Eventually(session).Should(Exit(0))
    90  				})
    91  			})
    92  
    93  			When("the app is stopped", func() {
    94  				BeforeEach(func() {
    95  					Eventually(helpers.CF("v3-stop", appName)).Should(Exit(0))
    96  				})
    97  
    98  				It("starts the app", func() {
    99  					userName, _ := helpers.GetCredentials()
   100  
   101  					session := helpers.CF("v3-restart", appName)
   102  					Eventually(session).Should(Say(`Starting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   103  					Eventually(session).Should(Say("OK"))
   104  
   105  					Eventually(session).Should(Exit(0))
   106  				})
   107  			})
   108  
   109  		})
   110  
   111  		When("the app does not exist", func() {
   112  			It("displays app not found and exits 1", func() {
   113  				invalidAppName := helpers.PrefixedRandomName("invalid-app")
   114  				session := helpers.CF("v3-restart", invalidAppName)
   115  
   116  				Eventually(session.Err).Should(Say("App '%s' not found", invalidAppName))
   117  				Eventually(session).Should(Say("FAILED"))
   118  
   119  				Eventually(session).Should(Exit(1))
   120  			})
   121  		})
   122  	})
   123  })