github.com/sleungcy/cli@v7.1.0+incompatible/integration/v7/isolated/cancel_deployment_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"code.cloudfoundry.org/cli/integration/helpers"
     7  
     8  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
     9  
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  	. "github.com/onsi/gomega/gbytes"
    13  	. "github.com/onsi/gomega/gexec"
    14  )
    15  
    16  var _ = Describe("Cancel Deployment", func() {
    17  	Context("Help", func() {
    18  		It("appears in cf help -a", func() {
    19  			session := helpers.CF("help", "-a")
    20  			Eventually(session).Should(Exit(0))
    21  			Expect(session).To(HaveCommandInCategoryWithDescription("cancel-deployment", "APPS", "Cancel the most recent deployment for an app. Resets the current droplet to the previous deployment's droplet."))
    22  		})
    23  
    24  		It("displays the help information", func() {
    25  			session := helpers.CF("cancel-deployment", "--help")
    26  			Eventually(session).Should(Say(`NAME:`))
    27  			Eventually(session).Should(Say(`cancel-deployment - Cancel the most recent deployment for an app. Resets the current droplet to the previous deployment's droplet.\n`))
    28  			Eventually(session).Should(Say(`\n`))
    29  
    30  			Eventually(session).Should(Say(`USAGE:`))
    31  			Eventually(session).Should(Say(`cf cancel-deployment APP_NAME\n`))
    32  			Eventually(session).Should(Say(`\n`))
    33  
    34  			Eventually(session).Should(Say(`EXAMPLES:`))
    35  			Eventually(session).Should(Say(`cf cancel-deployment my-app\n`))
    36  			Eventually(session).Should(Say(`\n`))
    37  
    38  			Eventually(session).Should(Say(`SEE ALSO:`))
    39  			Eventually(session).Should(Say(`app, push`))
    40  
    41  			Eventually(session).Should(Exit(0))
    42  		})
    43  	})
    44  
    45  	Context("when the environment is not set up correctly", func() {
    46  		It("fails with the appropriate errors", func() {
    47  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "cancel-deployment", "appName")
    48  		})
    49  	})
    50  
    51  	Context("When the environment is set up correctly", func() {
    52  		var (
    53  			orgName   string
    54  			spaceName string
    55  			appName   string
    56  			userName  string
    57  		)
    58  
    59  		BeforeEach(func() {
    60  			appName = helpers.NewAppName()
    61  			orgName = helpers.NewOrgName()
    62  			spaceName = helpers.NewSpaceName()
    63  
    64  			helpers.SetupCF(orgName, spaceName)
    65  			userName, _ = helpers.GetCredentials()
    66  
    67  			helpers.WithHelloWorldApp(func(appDir string) {
    68  				Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack", "-i", "3", "--no-start")).Should(Exit(0))
    69  			})
    70  		})
    71  
    72  		AfterEach(func() {
    73  			Eventually(helpers.CF("delete", appName, "-f")).Should(Exit(0))
    74  		})
    75  
    76  		Context("when there are no deployments", func() {
    77  			It("errors with a no deployments found error", func() {
    78  				session := helpers.CF("cancel-deployment", appName)
    79  				Eventually(session).Should(Say(fmt.Sprintf("Canceling deployment for app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)))
    80  				Eventually(session.Err).Should(Say(`No active deployment found for app\.`))
    81  				Eventually(session).Should(Say("FAILED"))
    82  				Eventually(session).Should(Exit(1))
    83  			})
    84  		})
    85  
    86  		Context("when the cancel is successful", func() {
    87  			BeforeEach(func() {
    88  				helpers.WithHelloWorldApp(func(appDir string) {
    89  					Eventually(helpers.CF("push", appName, "-p", appDir)).Should(Exit(0))
    90  				})
    91  			})
    92  
    93  			It("succeeds", func() {
    94  				helpers.WithHelloWorldApp(func(appDir string) {
    95  					Eventually(helpers.CF("push", appName, "-p", appDir, "--strategy=rolling", "--no-wait")).Should(Exit(0))
    96  				})
    97  
    98  				session := helpers.CF("cancel-deployment", appName)
    99  				Eventually(session).Should(Say(fmt.Sprintf("Canceling deployment for app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName)))
   100  				Eventually(session).Should(Say("OK"))
   101  				Eventually(session).Should(Say(fmt.Sprintf(`TIP: Run 'cf app %s' to view app status.`, appName)))
   102  				Eventually(session).Should(Exit(0))
   103  			})
   104  		})
   105  	})
   106  })