github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/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 _ = XDescribe("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  	Context("when the environment is not setup correctly", func() {
    41  		It("fails with the appropriate errors", func() {
    42  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "delete", "app-name")
    43  		})
    44  	})
    45  
    46  	Context("when the environment is setup correctly", func() {
    47  		var userName string
    48  
    49  		BeforeEach(func() {
    50  			setupCF(orgName, spaceName)
    51  			userName, _ = helpers.GetCredentials()
    52  		})
    53  
    54  		AfterEach(func() {
    55  			helpers.QuickDeleteOrg(orgName)
    56  		})
    57  
    58  		Context("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  		Context("when the app does not exist", func() {
    69  			It("prompts the user and displays app does not exist", func() {
    70  				buffer := NewBuffer()
    71  				buffer.Write([]byte("y\n"))
    72  				session := helpers.CFWithStdin(buffer, "delete")
    73  
    74  				Eventually(session).Should(Say("Really delete the app %s\\? \\[yN\\]", appName))
    75  				Eventually(session).Should(Say("Deleting app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
    76  				Eventually(session).Should(Say("OK"))
    77  				Eventually(session).Should(Say("App %s does not exist.", appName))
    78  				Eventually(session).Should(Exit(0))
    79  			})
    80  		})
    81  
    82  		Context("when the app exists", func() {
    83  			BeforeEach(func() {
    84  				helpers.WithHelloWorldApp(func(appDir string) {
    85  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName)).Should(Exit(0))
    86  				})
    87  			})
    88  
    89  			AfterEach(func() {
    90  				Eventually(helpers.CF("delete", appName, "-f", "-r")).Should(Exit(0))
    91  			})
    92  
    93  			Context("when the -f flag not is provided", func() {
    94  				var buffer *Buffer
    95  
    96  				BeforeEach(func() {
    97  					buffer = NewBuffer()
    98  				})
    99  
   100  				Context("when the user enters 'y'", func() {
   101  					BeforeEach(func() {
   102  						buffer.Write([]byte("y\n"))
   103  					})
   104  
   105  					It("deletes the app", func() {
   106  						session := helpers.CFWithStdin(buffer, "delete", appName)
   107  						Eventually(session).Should(Say("Really delete the app %s\\? \\[yN\\]", appName))
   108  						Eventually(session).Should(Say("Deleting app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   109  						Eventually(session).Should(Say("OK"))
   110  						Eventually(session).Should(Exit(0))
   111  						Eventually(helpers.CF("app", appName)).Should(Exit(1))
   112  					})
   113  				})
   114  
   115  				Context("when the user enters 'n'", func() {
   116  					BeforeEach(func() {
   117  						buffer.Write([]byte("n\n"))
   118  					})
   119  
   120  					It("does not delete the app", func() {
   121  						session := helpers.CFWithStdin(buffer, "delete", appName)
   122  						Eventually(session).Should(Say("Really delete the app %s\\? \\[yN\\]", appName))
   123  						Eventually(session).Should(Say("Delete cancelled"))
   124  						Eventually(session).Should(Say("OK"))
   125  						Eventually(session).Should(Exit(0))
   126  						Eventually(helpers.CF("app", appName)).Should(Exit(0))
   127  					})
   128  				})
   129  
   130  				Context("when the user enters the default input (hits return)", func() {
   131  					BeforeEach(func() {
   132  						buffer.Write([]byte("\n"))
   133  					})
   134  
   135  					It("does not delete the app", func() {
   136  						session := helpers.CFWithStdin(buffer, "delete", appName)
   137  						Eventually(session).Should(Say("Really delete the app %s\\? \\[yN\\]", appName))
   138  						Eventually(session).Should(Say("Delete cancelled"))
   139  						Eventually(session).Should(Say("OK"))
   140  						Eventually(session).Should(Exit(0))
   141  						Eventually(helpers.CF("app", appName)).Should(Exit(0))
   142  					})
   143  				})
   144  
   145  				Context("when the user enters an invalid answer", func() {
   146  					BeforeEach(func() {
   147  						// The second '\n' is intentional. Otherwise the buffer will be
   148  						// closed while the interaction is still waiting for input; it gets
   149  						// an EOF and causes an error.
   150  						buffer.Write([]byte("wat\n\n"))
   151  					})
   152  
   153  					It("asks again", func() {
   154  						session := helpers.CFWithStdin(buffer, "delete", appName)
   155  						Eventually(session).Should(Say("Really delete the app %s\\? \\[yN\\]", appName))
   156  						Eventually(session).Should(Say("invalid input \\(not y, n, yes, or no\\)"))
   157  						Eventually(session).Should(Say("Really delete the app %s\\? \\[yN\\]", appName))
   158  						Eventually(session).Should(Exit(0))
   159  						Eventually(helpers.CF("app", appName)).Should(Exit(0))
   160  					})
   161  				})
   162  			})
   163  
   164  			Context("when the -f flag is provided", func() {
   165  				It("deletes the app without prompting", func() {
   166  					session := helpers.CF("delete", appName, "-f")
   167  					Eventually(session).Should(Say("Deleting app %s in org %s / space %s as %s...", appName, orgName, spaceName, userName))
   168  					Eventually(session).Should(Say("Delete cancelled"))
   169  					Eventually(session).Should(Say("OK"))
   170  					Eventually(session).Should(Exit(0))
   171  					Eventually(helpers.CF("app", appName)).Should(Exit(1))
   172  				})
   173  			})
   174  		})
   175  	})
   176  })