github.com/sleungcy/cli@v7.1.0+incompatible/integration/v7/isolated/stop_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("stop 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("stop", "APPS", "Stop an app"))
    31  			})
    32  
    33  			It("Displays command usage to output", func() {
    34  				session := helpers.CF("stop", "--help")
    35  
    36  				Eventually(session).Should(Say("NAME:"))
    37  				Eventually(session).Should(Say("stop - Stop an app"))
    38  				Eventually(session).Should(Say("USAGE:"))
    39  				Eventually(session).Should(Say("cf stop APP_NAME"))
    40  				Eventually(session).Should(Say("ALIAS:"))
    41  				Eventually(session).Should(Say("sp"))
    42  				Eventually(session).Should(Say("SEE ALSO:"))
    43  				Eventually(session).Should(Say("restart, scale, start"))
    44  
    45  				Eventually(session).Should(Exit(0))
    46  			})
    47  		})
    48  	})
    49  
    50  	When("the app name is not provided", func() {
    51  		It("tells the user that the app name is required, prints help text, and exits 1", func() {
    52  			session := helpers.CF("stop")
    53  
    54  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    55  			Eventually(session).Should(Say("NAME:"))
    56  			Eventually(session).Should(Exit(1))
    57  		})
    58  	})
    59  
    60  	When("the environment is not setup correctly", func() {
    61  		It("fails with the appropriate errors", func() {
    62  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "stop", appName)
    63  		})
    64  	})
    65  
    66  	When("the environment is set up correctly", func() {
    67  		BeforeEach(func() {
    68  			helpers.SetupCF(orgName, spaceName)
    69  		})
    70  
    71  		AfterEach(func() {
    72  			helpers.QuickDeleteOrg(orgName)
    73  		})
    74  
    75  		When("the app exists", func() {
    76  			BeforeEach(func() {
    77  				helpers.WithHelloWorldApp(func(appDir string) {
    78  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)).Should(Exit(0))
    79  				})
    80  			})
    81  
    82  			It("stops the app", func() {
    83  				userName, _ := helpers.GetCredentials()
    84  
    85  				session := helpers.CF("stop", appName)
    86  				Eventually(session).Should(Say(`Stopping 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  			When("the app is already stopped", func() {
    93  				BeforeEach(func() {
    94  					Eventually(helpers.CF("stop", appName)).Should(Exit(0))
    95  				})
    96  
    97  				It("displays that the app is already stopped", func() {
    98  					session := helpers.CF("stop", appName)
    99  
   100  					Eventually(session).Should(Say(`App %s is already stopped\.`, appName))
   101  					Eventually(session).Should(Say("OK"))
   102  
   103  					Eventually(session).Should(Exit(0))
   104  				})
   105  			})
   106  
   107  			When("the app does not exist", func() {
   108  				It("displays app not found and exits 1", func() {
   109  					invalidAppName := "invalid-app-name"
   110  					session := helpers.CF("stop", invalidAppName)
   111  
   112  					Eventually(session.Err).Should(Say("App '%s' not found", invalidAppName))
   113  					Eventually(session).Should(Say("FAILED"))
   114  
   115  					Eventually(session).Should(Exit(1))
   116  				})
   117  			})
   118  		})
   119  	})
   120  })