github.com/wanddynosios/cli@v7.1.0+incompatible/integration/v6/experimental/v3_delete_command_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  )
    10  
    11  var _ = Describe("v3-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.PrefixedRandomName("app")
    22  	})
    23  
    24  	When("--help flag is set", func() {
    25  		It("Displays command usage to output", func() {
    26  			session := helpers.CF("v3-delete", "--help")
    27  			Eventually(session).Should(Say("NAME:"))
    28  			Eventually(session).Should(Say("v3-delete - Delete a V3 App"))
    29  			Eventually(session).Should(Say("USAGE:"))
    30  			Eventually(session).Should(Say(`cf v3-delete APP_NAME \[-f\]`))
    31  			Eventually(session).Should(Say("OPTIONS:"))
    32  			Eventually(session).Should(Say(`\s+-f\s+Force deletion without confirmation`))
    33  			Eventually(session).Should(Exit(0))
    34  		})
    35  	})
    36  
    37  	When("the app name is not provided", func() {
    38  		It("tells the user that the app name is required, prints help text, and exits 1", func() {
    39  			session := helpers.CF("v3-delete")
    40  
    41  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    42  			Eventually(session).Should(Say("NAME:"))
    43  			Eventually(session).Should(Exit(1))
    44  		})
    45  	})
    46  
    47  	It("displays the experimental warning", func() {
    48  		session := helpers.CF("v3-delete", appName)
    49  		Eventually(session.Err).Should(Say("This command is in EXPERIMENTAL stage and may change without notice"))
    50  		Eventually(session).Should(Exit())
    51  	})
    52  
    53  	When("the environment is not setup correctly", func() {
    54  		When("no API endpoint is set", func() {
    55  			BeforeEach(func() {
    56  				helpers.UnsetAPI()
    57  			})
    58  
    59  			It("fails with no API endpoint set message", func() {
    60  				session := helpers.CF("v3-delete", appName)
    61  				Eventually(session).Should(Say("FAILED"))
    62  				Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint."))
    63  				Eventually(session).Should(Exit(1))
    64  			})
    65  		})
    66  
    67  		When("not logged in", func() {
    68  			BeforeEach(func() {
    69  				helpers.LogoutCF()
    70  			})
    71  
    72  			It("fails with not logged in message", func() {
    73  				session := helpers.CF("v3-delete", appName)
    74  				Eventually(session).Should(Say("FAILED"))
    75  				Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' or 'cf login --sso' to log in."))
    76  				Eventually(session).Should(Exit(1))
    77  			})
    78  		})
    79  
    80  		When("there is no org set", func() {
    81  			BeforeEach(func() {
    82  				helpers.LogoutCF()
    83  				helpers.LoginCF()
    84  			})
    85  
    86  			It("fails with no targeted org error message", func() {
    87  				session := helpers.CF("v3-delete", appName)
    88  				Eventually(session).Should(Say("FAILED"))
    89  				Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org."))
    90  				Eventually(session).Should(Exit(1))
    91  			})
    92  		})
    93  
    94  		When("there is no space set", func() {
    95  			BeforeEach(func() {
    96  				helpers.LogoutCF()
    97  				helpers.LoginCF()
    98  				helpers.TargetOrg(ReadOnlyOrg)
    99  			})
   100  
   101  			It("fails with no targeted space error message", func() {
   102  				session := helpers.CF("v3-delete", appName)
   103  				Eventually(session).Should(Say("FAILED"))
   104  				Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space."))
   105  				Eventually(session).Should(Exit(1))
   106  			})
   107  		})
   108  	})
   109  
   110  	When("the environment is setup correctly", func() {
   111  		BeforeEach(func() {
   112  			helpers.SetupCF(orgName, spaceName)
   113  		})
   114  
   115  		AfterEach(func() {
   116  			helpers.QuickDeleteOrg(orgName)
   117  		})
   118  
   119  		When("the app does not exist", func() {
   120  			When("the -f flag is provided", func() {
   121  				It("it displays the app does not exist", func() {
   122  					username, _ := helpers.GetCredentials()
   123  					session := helpers.CF("v3-delete", appName, "-f")
   124  					Eventually(session).Should(Say("Deleting app %s in org %s / space %s as %s...", appName, orgName, spaceName, username))
   125  					Eventually(session).Should(Say("App %s does not exist", appName))
   126  					Eventually(session).Should(Say("OK"))
   127  					Eventually(session).Should(Exit(0))
   128  				})
   129  			})
   130  
   131  			When("the -f flag not is provided", func() {
   132  				var buffer *Buffer
   133  
   134  				BeforeEach(func() {
   135  					buffer = NewBuffer()
   136  				})
   137  
   138  				When("the user enters 'y'", func() {
   139  					BeforeEach(func() {
   140  						_, err := buffer.Write([]byte("y\n"))
   141  						Expect(err).NotTo(HaveOccurred())
   142  					})
   143  
   144  					It("it displays the app does not exist", func() {
   145  						username, _ := helpers.GetCredentials()
   146  						session := helpers.CFWithStdin(buffer, "v3-delete", appName)
   147  						Eventually(session).Should(Say(`Really delete the app %s\? \[yN\]`, appName))
   148  						Eventually(session).Should(Say("Deleting app %s in org %s / space %s as %s...", appName, orgName, spaceName, username))
   149  						Eventually(session).Should(Say("App %s does not exist", appName))
   150  						Eventually(session).Should(Say("OK"))
   151  						Eventually(session).Should(Exit(0))
   152  					})
   153  				})
   154  
   155  				When("the user enters 'n'", func() {
   156  					BeforeEach(func() {
   157  						_, err := buffer.Write([]byte("n\n"))
   158  						Expect(err).NotTo(HaveOccurred())
   159  					})
   160  
   161  					It("does not delete the app", func() {
   162  						session := helpers.CFWithStdin(buffer, "v3-delete", appName)
   163  						Eventually(session).Should(Say(`Really delete the app %s\? \[yN\]`, appName))
   164  						Eventually(session).Should(Say("Delete cancelled"))
   165  						Eventually(session).Should(Exit(0))
   166  					})
   167  				})
   168  
   169  				When("the user enters the default input (hits return)", func() {
   170  					BeforeEach(func() {
   171  						_, err := buffer.Write([]byte("\n"))
   172  						Expect(err).NotTo(HaveOccurred())
   173  					})
   174  
   175  					It("does not delete the app", func() {
   176  						session := helpers.CFWithStdin(buffer, "v3-delete", appName)
   177  						Eventually(session).Should(Say(`Really delete the app %s\? \[yN\]`, appName))
   178  						Eventually(session).Should(Say("Delete cancelled"))
   179  						Eventually(session).Should(Exit(0))
   180  					})
   181  				})
   182  
   183  				When("the user enters an invalid answer", func() {
   184  					BeforeEach(func() {
   185  						// The second '\n' is intentional. Otherwise the buffer will be
   186  						// closed while the interaction is still waiting for input; it gets
   187  						// an EOF and causes an error.
   188  						_, err := buffer.Write([]byte("wat\n\n"))
   189  						Expect(err).NotTo(HaveOccurred())
   190  					})
   191  
   192  					It("asks again", func() {
   193  						session := helpers.CFWithStdin(buffer, "v3-delete", appName)
   194  						Eventually(session).Should(Say(`Really delete the app %s\? \[yN\]`, appName))
   195  						Eventually(session).Should(Say(`invalid input \(not y, n, yes, or no\)`))
   196  						Eventually(session).Should(Say(`Really delete the app %s\? \[yN\]`, appName))
   197  						Eventually(session).Should(Exit(0))
   198  					})
   199  				})
   200  			})
   201  		})
   202  
   203  		When("the app exists", func() {
   204  			BeforeEach(func() {
   205  				helpers.WithHelloWorldApp(func(appDir string) {
   206  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)).Should(Exit(0))
   207  				})
   208  			})
   209  
   210  			It("deletes the app", func() {
   211  				session := helpers.CF("v3-delete", appName, "-f")
   212  				username, _ := helpers.GetCredentials()
   213  				Eventually(session).Should(Say("Deleting app %s in org %s / space %s as %s...", appName, orgName, spaceName, username))
   214  				Eventually(session).Should(Say("OK"))
   215  				Eventually(session).Should(Exit(0))
   216  
   217  				Eventually(helpers.CF("v3-app", appName)).Should(Exit(1))
   218  			})
   219  		})
   220  	})
   221  })