github.com/wanddynosios/cli@v7.1.0+incompatible/integration/v6/experimental/v3_zdt_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  	. "github.com/onsi/gomega/ghttp"
    10  )
    11  
    12  var _ = Describe("v3-zdt-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("displays command usage to output", func() {
    28  				session := helpers.CF("v3-zdt-restart", "--help")
    29  
    30  				Eventually(session).Should(Say("NAME:"))
    31  				Eventually(session).Should(Say(`v3-zdt-restart - Sequentially restart each instance of an app\.`))
    32  				Eventually(session).Should(Say("USAGE:"))
    33  				Eventually(session).Should(Say("cf v3-zdt-restart APP_NAME"))
    34  
    35  				Eventually(session).Should(Exit(0))
    36  			})
    37  		})
    38  	})
    39  
    40  	When("the app name is not provided", func() {
    41  		It("tells the user that the app name is required, prints help text, and exits 1", func() {
    42  			session := helpers.CF("v3-zdt-restart")
    43  
    44  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    45  			Eventually(session).Should(Say("NAME:"))
    46  			Eventually(session).Should(Exit(1))
    47  		})
    48  	})
    49  
    50  	It("displays the experimental warning", func() {
    51  		session := helpers.CF("v3-zdt-restart", appName)
    52  		Eventually(session.Err).Should(Say("This command is in EXPERIMENTAL stage and may change without notice"))
    53  		Eventually(session).Should(Exit())
    54  	})
    55  
    56  	When("the environment is not setup correctly", func() {
    57  		When("the v3 api version is lower than the minimum version", func() {
    58  			var server *Server
    59  
    60  			BeforeEach(func() {
    61  				server = helpers.StartAndTargetMockServerWithAPIVersions(helpers.DefaultV2Version, "3.0.0")
    62  			})
    63  
    64  			AfterEach(func() {
    65  				server.Close()
    66  			})
    67  
    68  			It("fails with error message that the minimum version is not met", func() {
    69  				session := helpers.CF("v3-zdt-restart", appName)
    70  				Eventually(session).Should(Say("FAILED"))
    71  				Eventually(session.Err).Should(Say(`This command requires CF API version 3\.63\.0 or higher\.`))
    72  				Eventually(session).Should(Exit(1))
    73  			})
    74  		})
    75  
    76  		It("fails with the appropriate errors", func() {
    77  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "v3-zdt-restart", appName)
    78  		})
    79  	})
    80  
    81  	When("the environment is set up correctly", func() {
    82  		BeforeEach(func() {
    83  			helpers.SetupCF(orgName, spaceName)
    84  		})
    85  
    86  		AfterEach(func() {
    87  			helpers.QuickDeleteOrg(orgName)
    88  		})
    89  
    90  		When("the app exists", func() {
    91  			BeforeEach(func() {
    92  				helpers.WithHelloWorldApp(func(appDir string) {
    93  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)).Should(Exit(0))
    94  				})
    95  			})
    96  
    97  			When("the app is running", func() {
    98  				It("starts a deployment of the app", func() {
    99  					userName, _ := helpers.GetCredentials()
   100  
   101  					session := helpers.CF("v3-zdt-restart", appName)
   102  					Eventually(session).Should(Say(`Starting deployment for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   103  					Eventually(session).Should(Say(`Waiting for app to start\.\.\.`))
   104  					Eventually(session).Should(Say("OK"))
   105  
   106  					Eventually(session).Should(Exit(0))
   107  				})
   108  			})
   109  
   110  			When("the app is stopped", func() {
   111  				BeforeEach(func() {
   112  					Eventually(helpers.CF("v3-stop", appName)).Should(Exit(0))
   113  				})
   114  
   115  				It("errors", func() {
   116  					userName, _ := helpers.GetCredentials()
   117  
   118  					session := helpers.CF("v3-zdt-restart", appName)
   119  					Eventually(session).Should(Say(`Starting app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   120  					Eventually(session).Should(Say("OK"))
   121  
   122  					Eventually(session).Should(Exit(0))
   123  				})
   124  			})
   125  
   126  		})
   127  
   128  		When("the app does not exist", func() {
   129  			It("displays app not found and exits 1", func() {
   130  				invalidAppName := helpers.PrefixedRandomName("invalid-app")
   131  				session := helpers.CF("v3-zdt-restart", invalidAppName)
   132  
   133  				Eventually(session.Err).Should(Say("App '%s' not found", invalidAppName))
   134  				Eventually(session).Should(Say("FAILED"))
   135  
   136  				Eventually(session).Should(Exit(1))
   137  			})
   138  		})
   139  	})
   140  })