github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/v6/experimental/v3_cancel_zdt_push_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-cancel-zdt-push 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.NewAppName()
    23  		helpers.TurnOffExperimental()
    24  	})
    25  
    26  	AfterEach(func() {
    27  		helpers.TurnOnExperimental()
    28  	})
    29  
    30  	Describe("help", func() {
    31  		Context("when --help flag is set", func() {
    32  			It("Displays command usage to output", func() {
    33  				session := helpers.CF("v3-cancel-zdt-push", "--help")
    34  				Eventually(session).Should(Say("NAME:"))
    35  				Eventually(session).Should(Say("v3-cancel-zdt-push - Cancel the most recent deployment for an app"))
    36  				Eventually(session).Should(Say("USAGE:"))
    37  				Eventually(session).Should(Say("cf v3-cancel-zdt-push APP_NAME"))
    38  				Eventually(session).Should(Exit(0))
    39  			})
    40  		})
    41  	})
    42  
    43  	Context("when the environment is not setup correctly", func() {
    44  		When("the v3 api version is lower than the minimum version", func() {
    45  			var server *Server
    46  
    47  			BeforeEach(func() {
    48  				server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, "3.0.0")
    49  			})
    50  
    51  			AfterEach(func() {
    52  				server.Close()
    53  			})
    54  
    55  			It("fails with error message that the minimum version is not met", func() {
    56  				session := helpers.CF("v3-cancel-zdt-push", appName)
    57  				Eventually(session).Should(Say("FAILED"))
    58  				Eventually(session.Err).Should(Say(`This command requires CF API version 3\.27\.0 or higher\.`))
    59  				Eventually(session).Should(Exit(1))
    60  			})
    61  		})
    62  
    63  		It("fails with the appropriate errors", func() {
    64  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "v3-cancel-zdt-push", appName)
    65  		})
    66  	})
    67  
    68  	Context("when the environment is set up correctly", func() {
    69  
    70  		BeforeEach(func() {
    71  			helpers.SetupCF(orgName, spaceName)
    72  		})
    73  
    74  		AfterEach(func() {
    75  			helpers.QuickDeleteOrg(orgName)
    76  		})
    77  
    78  		Context("when the app name is not provided", func() {
    79  			It("tells the user that the app name is required, prints help text, and exits 1", func() {
    80  				session := helpers.CF("v3-cancel-zdt-push")
    81  
    82  				Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    83  				Eventually(session).Should(Say("NAME:"))
    84  				Eventually(session).Should(Exit(1))
    85  			})
    86  		})
    87  
    88  		It("displays the experimental warning", func() {
    89  			session := helpers.CF("v3-cancel-zdt-push", appName)
    90  			Eventually(session.Err).Should(Say("This command is in EXPERIMENTAL stage and may change without notice"))
    91  			Eventually(session).Should(Exit())
    92  		})
    93  
    94  		Context("when there is no org set", func() {
    95  			BeforeEach(func() {
    96  				helpers.LogoutCF()
    97  				helpers.LoginCF()
    98  			})
    99  
   100  			It("fails with no org targeted error message", func() {
   101  				session := helpers.CF("v3-cancel-zdt-push", appName)
   102  				Eventually(session).Should(Say("FAILED"))
   103  				Eventually(session.Err).Should(Say(`No org targeted, use 'cf target -o ORG' to target an org\.`))
   104  				Eventually(session).Should(Exit(1))
   105  			})
   106  		})
   107  
   108  		Context("when there is no space set", func() {
   109  			BeforeEach(func() {
   110  				helpers.LogoutCF()
   111  				helpers.LoginCF()
   112  				helpers.TargetOrg(ReadOnlyOrg)
   113  			})
   114  
   115  			It("fails with no space targeted error message", func() {
   116  				session := helpers.CF("v3-cancel-zdt-push", appName)
   117  				Eventually(session).Should(Say("FAILED"))
   118  				Eventually(session.Err).Should(Say(`No space targeted, use 'cf target -s SPACE' to target a space\.`))
   119  				Eventually(session).Should(Exit(1))
   120  			})
   121  		})
   122  
   123  		Context("when there is no org set", func() {
   124  			BeforeEach(func() {
   125  				helpers.LogoutCF()
   126  				helpers.LoginCF()
   127  			})
   128  
   129  			It("fails with no org targeted error message", func() {
   130  				session := helpers.CF("v3-cancel-zdt-push", appName)
   131  				Eventually(session).Should(Say("FAILED"))
   132  				Eventually(session.Err).Should(Say(`No org targeted, use 'cf target -o ORG' to target an org\.`))
   133  				Eventually(session).Should(Exit(1))
   134  			})
   135  		})
   136  
   137  		Context("when there is no space set", func() {
   138  			BeforeEach(func() {
   139  				helpers.LogoutCF()
   140  				helpers.LoginCF()
   141  				helpers.TargetOrg(ReadOnlyOrg)
   142  			})
   143  
   144  			It("fails with no space targeted error message", func() {
   145  				session := helpers.CF("v3-cancel-zdt-push", appName)
   146  				Eventually(session).Should(Say("FAILED"))
   147  				Eventually(session.Err).Should(Say(`No space targeted, use 'cf target -s SPACE' to target a space\.`))
   148  				Eventually(session).Should(Exit(1))
   149  			})
   150  		})
   151  
   152  		Context("when there is no org set", func() {
   153  			BeforeEach(func() {
   154  				helpers.LogoutCF()
   155  				helpers.LoginCF()
   156  			})
   157  
   158  			It("fails with no org targeted error message", func() {
   159  				session := helpers.CF("v3-cancel-zdt-push", appName)
   160  				Eventually(session).Should(Say("FAILED"))
   161  				Eventually(session.Err).Should(Say(`No org targeted, use 'cf target -o ORG' to target an org\.`))
   162  				Eventually(session).Should(Exit(1))
   163  			})
   164  		})
   165  
   166  		Context("when there is no space set", func() {
   167  			BeforeEach(func() {
   168  				helpers.LogoutCF()
   169  				helpers.LoginCF()
   170  				helpers.TargetOrg(ReadOnlyOrg)
   171  			})
   172  
   173  			It("fails with no space targeted error message", func() {
   174  				session := helpers.CF("v3-cancel-zdt-push", appName)
   175  				Eventually(session).Should(Say("FAILED"))
   176  				Eventually(session.Err).Should(Say(`No space targeted, use 'cf target -s SPACE' to target a space\.`))
   177  				Eventually(session).Should(Exit(1))
   178  			})
   179  		})
   180  
   181  		Context("when the app exists", func() {
   182  			var session *Session
   183  
   184  			BeforeEach(func() {
   185  				helpers.WithHelloWorldApp(func(appDir string) {
   186  					session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName)
   187  					Eventually(session).Should(Exit(0))
   188  				})
   189  			})
   190  
   191  			Context("and it is currently deploying", func() {
   192  				BeforeEach(func() {
   193  					// zdt-push a crashing app so that underlying deployment never goes from DEPLOYING -> DEPLOYED
   194  					helpers.WithCrashingApp(func(appDir string) {
   195  						session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-zdt-push", appName)
   196  						Eventually(session).Should(Exit(0))
   197  					})
   198  				})
   199  
   200  				It("cancels the deployment", func() {
   201  					session := helpers.CF("v3-cancel-zdt-push", appName)
   202  					Eventually(session).Should(Exit(0))
   203  					Eventually(session).Should(Say("Deployment cancelled, rolling back"))
   204  				})
   205  			})
   206  
   207  			Context("when the app has no deployment to cancel", func() {
   208  				It("errors", func() {
   209  					session := helpers.CF("v3-cancel-zdt-push", appName)
   210  					Eventually(session).Should(Exit(1))
   211  					Eventually(session.Err).Should(Say("failed to find a deployment for that app"))
   212  				})
   213  			})
   214  		})
   215  	})
   216  })