github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/shared/experimental/v3_restart_command_test.go (about)

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