github.com/willmadison/cli@v6.40.1-0.20181018160101-29d5937903ff+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("no API endpoint is set", func() {
    61  			BeforeEach(func() {
    62  				helpers.UnsetAPI()
    63  			})
    64  
    65  			It("fails with no API endpoint set message", func() {
    66  				session := helpers.CF("v3-restart", appName)
    67  				Eventually(session).Should(Say("FAILED"))
    68  				Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\."))
    69  				Eventually(session).Should(Exit(1))
    70  			})
    71  		})
    72  
    73  		When("the v3 api version is lower than the minimum version", func() {
    74  			var server *Server
    75  
    76  			BeforeEach(func() {
    77  				server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, ccversion.MinV3ClientVersion)
    78  			})
    79  
    80  			AfterEach(func() {
    81  				server.Close()
    82  			})
    83  
    84  			It("fails with error message that the minimum version is not met", func() {
    85  				session := helpers.CF("v3-restart", appName)
    86  				Eventually(session).Should(Say("FAILED"))
    87  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\."))
    88  				Eventually(session).Should(Exit(1))
    89  			})
    90  		})
    91  
    92  		When("not logged in", func() {
    93  			BeforeEach(func() {
    94  				helpers.LogoutCF()
    95  			})
    96  
    97  			It("fails with not logged in message", func() {
    98  				session := helpers.CF("v3-restart", appName)
    99  				Eventually(session).Should(Say("FAILED"))
   100  				Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\."))
   101  				Eventually(session).Should(Exit(1))
   102  			})
   103  		})
   104  
   105  		When("there is no org set", func() {
   106  			BeforeEach(func() {
   107  				helpers.LogoutCF()
   108  				helpers.LoginCF()
   109  			})
   110  
   111  			It("fails with no org targeted error message", func() {
   112  				session := helpers.CF("v3-restart", appName)
   113  				Eventually(session).Should(Say("FAILED"))
   114  				Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org\\."))
   115  				Eventually(session).Should(Exit(1))
   116  			})
   117  		})
   118  
   119  		When("there is no space set", func() {
   120  			BeforeEach(func() {
   121  				helpers.LogoutCF()
   122  				helpers.LoginCF()
   123  				helpers.TargetOrg(ReadOnlyOrg)
   124  			})
   125  
   126  			It("fails with no space targeted error message", func() {
   127  				session := helpers.CF("v3-restart", appName)
   128  				Eventually(session).Should(Say("FAILED"))
   129  				Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space\\."))
   130  				Eventually(session).Should(Exit(1))
   131  			})
   132  		})
   133  	})
   134  
   135  	When("the environment is set up correctly", func() {
   136  		BeforeEach(func() {
   137  			helpers.SetupCF(orgName, spaceName)
   138  		})
   139  
   140  		AfterEach(func() {
   141  			helpers.QuickDeleteOrg(orgName)
   142  		})
   143  
   144  		When("the app exists", func() {
   145  			BeforeEach(func() {
   146  				helpers.WithHelloWorldApp(func(appDir string) {
   147  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)).Should(Exit(0))
   148  				})
   149  			})
   150  
   151  			When("the app is running", func() {
   152  				It("stops then restarts the app", func() {
   153  					userName, _ := helpers.GetCredentials()
   154  
   155  					session := helpers.CF("v3-restart", appName)
   156  					Eventually(session).Should(Say("Stopping app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName))
   157  					Eventually(session).Should(Say("OK"))
   158  					Eventually(session).Should(Say("Starting app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName))
   159  					Eventually(session).Should(Say("OK"))
   160  
   161  					Eventually(session).Should(Exit(0))
   162  				})
   163  			})
   164  
   165  			When("the app is stopped", func() {
   166  				BeforeEach(func() {
   167  					Eventually(helpers.CF("v3-stop", appName)).Should(Exit(0))
   168  				})
   169  
   170  				It("starts the app", func() {
   171  					userName, _ := helpers.GetCredentials()
   172  
   173  					session := helpers.CF("v3-restart", appName)
   174  					Eventually(session).Should(Say("Starting app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName))
   175  					Eventually(session).Should(Say("OK"))
   176  
   177  					Eventually(session).Should(Exit(0))
   178  				})
   179  			})
   180  
   181  		})
   182  
   183  		When("the app does not exist", func() {
   184  			It("displays app not found and exits 1", func() {
   185  				invalidAppName := helpers.PrefixedRandomName("invalid-app")
   186  				session := helpers.CF("v3-restart", invalidAppName)
   187  
   188  				Eventually(session.Err).Should(Say("App %s not found", invalidAppName))
   189  				Eventually(session).Should(Say("FAILED"))
   190  
   191  				Eventually(session).Should(Exit(1))
   192  			})
   193  		})
   194  	})
   195  })