github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v6/isolated/delete_command_test.go (about)

     1  package isolated
     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  )
    10  
    11  var _ = Describe("delete command", func() {
    12  	var (
    13  		orgName   string
    14  		spaceName string
    15  		appName   string
    16  	)
    17  
    18  	BeforeEach(func() {
    19  		orgName = helpers.NewOrgName()
    20  		spaceName = helpers.NewSpaceName()
    21  		appName = helpers.NewAppName()
    22  	})
    23  
    24  	Describe("help", func() {
    25  		It("shows usage", func() {
    26  			session := helpers.CF("help", "delete")
    27  			Eventually(session).Should(Say("NAME:"))
    28  			Eventually(session).Should(Say("\\s+delete - Delete an app"))
    29  			Eventually(session).Should(Say("USAGE:"))
    30  			Eventually(session).Should(Say("cf delete APP_NAME \\[-r\\] \\[-f\\]"))
    31  			Eventually(session).Should(Say("OPTIONS:"))
    32  			Eventually(session).Should(Say("\\s+-f\\s+Force deletion without confirmation"))
    33  			Eventually(session).Should(Say("\\s+-r\\s+Also delete any mapped routes"))
    34  			Eventually(session).Should(Say("SEE ALSO:"))
    35  			Eventually(session).Should(Say("apps, scale, stop"))
    36  			Eventually(session).Should(Exit(0))
    37  		})
    38  	})
    39  
    40  	When("the environment is not setup correctly", func() {
    41  		It("fails with the appropriate errors", func() {
    42  			helpers.UnrefactoredCheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "delete", "app-name")
    43  		})
    44  	})
    45  
    46  	When("the environment is setup correctly", func() {
    47  		var userName string
    48  
    49  		BeforeEach(func() {
    50  			helpers.SetupCF(orgName, spaceName)
    51  			userName, _ = helpers.GetCredentials()
    52  		})
    53  
    54  		AfterEach(func() {
    55  			helpers.QuickDeleteOrg(orgName)
    56  		})
    57  
    58  		When("the app name is not provided", func() {
    59  			It("tells the user that the app name is required, prints help text, and exits 1", func() {
    60  				session := helpers.CF("delete")
    61  
    62  				Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    63  				Eventually(session).Should(Say("NAME:"))
    64  				Eventually(session).Should(Exit(1))
    65  			})
    66  		})
    67  
    68  		When("the app does not exist", func() {
    69  			It("displays that the app does not exist", func() {
    70  				session := helpers.CF("delete", appName, "-f")
    71  
    72  				Eventually(session).Should(Say("Deleting app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
    73  				Eventually(session).Should(Say("OK"))
    74  				Eventually(session).Should(Say("App %s does not exist.", appName))
    75  				Eventually(session).Should(Exit(0))
    76  			})
    77  		})
    78  
    79  		When("the app exists", func() {
    80  			BeforeEach(func() {
    81  				helpers.WithHelloWorldApp(func(appDir string) {
    82  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName)).Should(Exit(0))
    83  				})
    84  			})
    85  
    86  			AfterEach(func() {
    87  				Eventually(helpers.CF("delete", appName, "-f", "-r")).Should(Exit(0))
    88  			})
    89  
    90  			When("the -f flag not is provided", func() {
    91  				var buffer *Buffer
    92  
    93  				BeforeEach(func() {
    94  					buffer = NewBuffer()
    95  				})
    96  
    97  				When("the user enters the default input (hits return)", func() {
    98  					BeforeEach(func() {
    99  						buffer.Write([]byte("\n"))
   100  					})
   101  
   102  					It("does not delete the app", func() {
   103  						session := helpers.CFWithStdin(buffer, "delete", appName)
   104  						Eventually(session).Should(Say("Really delete the app %s\\?", appName))
   105  						Eventually(session).Should(Say("Delete cancelled"))
   106  						Eventually(session).Should(Exit(0))
   107  						Eventually(helpers.CF("app", appName)).Should(Exit(0))
   108  					})
   109  				})
   110  
   111  			})
   112  
   113  			When("the -f flag is provided", func() {
   114  				It("deletes the app without prompting", func() {
   115  					session := helpers.CF("delete", appName, "-f")
   116  					Eventually(session).Should(Say("Deleting app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   117  					Eventually(session).Should(Say("OK"))
   118  					Eventually(session).Should(Exit(0))
   119  					Eventually(helpers.CF("app", appName)).Should(Exit(1))
   120  				})
   121  			})
   122  		})
   123  	})
   124  })