github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/v6/isolated/delete_org_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-org command", func() {
    12  	When("the environment is not setup correctly", func() {
    13  		It("fails with the appropriate errors", func() {
    14  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "delete-org", "some-org")
    15  		})
    16  	})
    17  
    18  	When("the org name is not provided", func() {
    19  		It("displays an error and help", func() {
    20  			session := helpers.CF("delete-org")
    21  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `ORG` was not provided"))
    22  			Eventually(session).Should(Say("USAGE"))
    23  			Eventually(session).Should(Exit(1))
    24  		})
    25  	})
    26  
    27  	When("the org does not exist", func() {
    28  		BeforeEach(func() {
    29  			helpers.LoginCF()
    30  		})
    31  
    32  		It("displays a warning and exits 0", func() {
    33  			username, _ := helpers.GetCredentials()
    34  			session := helpers.CF("delete-org", "-f", "please-do-not-exist-in-real-life")
    35  			Eventually(session).Should(Say("Deleting org please-do-not-exist-in-real-life as %s...", username))
    36  			Eventually(session).Should(Say("Org please-do-not-exist-in-real-life does not exist."))
    37  			Eventually(session).Should(Say("OK"))
    38  			Eventually(session).Should(Exit(0))
    39  		})
    40  	})
    41  
    42  	When("the org exists", func() {
    43  		var orgName string
    44  
    45  		BeforeEach(func() {
    46  			helpers.LoginCF()
    47  
    48  			orgName = helpers.NewOrgName()
    49  			helpers.CreateOrgAndSpace(orgName, helpers.NewSpaceName())
    50  		})
    51  
    52  		AfterEach(func() {
    53  			helpers.QuickDeleteOrgIfExists(orgName)
    54  		})
    55  
    56  		When("the -f flag not is provided", func() {
    57  			var buffer *Buffer
    58  
    59  			BeforeEach(func() {
    60  				buffer = NewBuffer()
    61  			})
    62  
    63  			When("the user enters 'y'", func() {
    64  				BeforeEach(func() {
    65  					_, err := buffer.Write([]byte("y\n"))
    66  					Expect(err).ToNot(HaveOccurred())
    67  				})
    68  
    69  				It("deletes the org", func() {
    70  					username, _ := helpers.GetCredentials()
    71  					session := helpers.CFWithStdin(buffer, "delete-org", orgName)
    72  					Eventually(session).Should(Say(`Really delete the org %s, including its spaces, apps, service instances, routes, private domains and space-scoped service brokers\?`, orgName))
    73  					Eventually(session).Should(Say("Deleting org %s as %s...", orgName, username))
    74  					Eventually(session).Should(Say("OK"))
    75  					Eventually(session).Should(Exit(0))
    76  					Eventually(helpers.CF("org", orgName)).Should(Exit(1))
    77  				})
    78  			})
    79  
    80  			When("the user enters 'n'", func() {
    81  				BeforeEach(func() {
    82  					_, err := buffer.Write([]byte("n\n"))
    83  					Expect(err).ToNot(HaveOccurred())
    84  				})
    85  
    86  				It("does not delete the org", func() {
    87  					session := helpers.CFWithStdin(buffer, "delete-org", orgName)
    88  					Eventually(session).Should(Say(`Really delete the org %s, including its spaces, apps, service instances, routes, private domains and space-scoped service brokers\?`, orgName))
    89  					Eventually(session).Should(Say("Delete cancelled"))
    90  					Eventually(session).Should(Exit(0))
    91  					Eventually(helpers.CF("org", orgName)).Should(Exit(0))
    92  				})
    93  			})
    94  
    95  			When("the user enters the default input (hits return)", func() {
    96  				BeforeEach(func() {
    97  					_, err := buffer.Write([]byte("\n"))
    98  					Expect(err).ToNot(HaveOccurred())
    99  				})
   100  
   101  				It("does not delete the org", func() {
   102  					session := helpers.CFWithStdin(buffer, "delete-org", orgName)
   103  					Eventually(session).Should(Say(`Really delete the org %s, including its spaces, apps, service instances, routes, private domains and space-scoped service brokers\?`, orgName))
   104  					Eventually(session).Should(Say("Delete cancelled"))
   105  					Eventually(session).Should(Exit(0))
   106  					Eventually(helpers.CF("org", orgName)).Should(Exit(0))
   107  				})
   108  			})
   109  
   110  			When("the user enters an invalid answer", func() {
   111  				BeforeEach(func() {
   112  					// The second '\n' is intentional. Otherwise the buffer will be
   113  					// closed while the interaction is still waiting for input; it gets
   114  					// an EOF and causes an error.
   115  					_, err := buffer.Write([]byte("wat\n\n"))
   116  					Expect(err).ToNot(HaveOccurred())
   117  				})
   118  
   119  				It("asks again", func() {
   120  					session := helpers.CFWithStdin(buffer, "delete-org", orgName)
   121  					Eventually(session).Should(Say(`Really delete the org %s, including its spaces, apps, service instances, routes, private domains and space-scoped service brokers\?`, orgName))
   122  					Eventually(session).Should(Say(`invalid input \(not y, n, yes, or no\)`))
   123  					Eventually(session).Should(Say(`Really delete the org %s, including its spaces, apps, service instances, routes, private domains and space-scoped service brokers\?`, orgName))
   124  					Eventually(session).Should(Exit(0))
   125  					Eventually(helpers.CF("org", orgName)).Should(Exit(0))
   126  				})
   127  			})
   128  		})
   129  
   130  		When("the -f flag is provided", func() {
   131  			It("deletes the org", func() {
   132  				username, _ := helpers.GetCredentials()
   133  				session := helpers.CF("delete-org", orgName, "-f")
   134  				Eventually(session).Should(Say("Deleting org %s as %s...", orgName, username))
   135  				Eventually(session).Should(Say("OK"))
   136  				Eventually(session).Should(Exit(0))
   137  				Eventually(helpers.CF("org", orgName)).Should(Exit(1))
   138  			})
   139  		})
   140  	})
   141  
   142  	When("deleting an org that is targeted", func() {
   143  		var orgName string
   144  
   145  		BeforeEach(func() {
   146  			helpers.LoginCF()
   147  
   148  			orgName = helpers.NewOrgName()
   149  			spaceName := helpers.NewSpaceName()
   150  			helpers.CreateOrgAndSpace(orgName, spaceName)
   151  			helpers.TargetOrgAndSpace(orgName, spaceName)
   152  		})
   153  
   154  		AfterEach(func() {
   155  			helpers.QuickDeleteOrgIfExists(orgName)
   156  		})
   157  
   158  		It("clears the targeted org and space", func() {
   159  			session := helpers.CF("delete-org", orgName, "-f")
   160  			Eventually(session).Should(Exit(0))
   161  
   162  			session = helpers.CF("target")
   163  			Eventually(session).Should(Say("No org or space targeted, use 'cf target -o ORG -s SPACE'"))
   164  			Eventually(session).Should(Exit(0))
   165  		})
   166  	})
   167  
   168  	When("deleting an org that is not targeted", func() {
   169  		var orgName string
   170  
   171  		BeforeEach(func() {
   172  			helpers.LoginCF()
   173  
   174  			orgName = helpers.NewOrgName()
   175  			helpers.TargetOrgAndSpace(ReadOnlyOrg, ReadOnlySpace)
   176  		})
   177  
   178  		It("does not clear the targeted org and space", func() {
   179  			session := helpers.CF("delete-org", orgName, "-f")
   180  			Eventually(session).Should(Exit(0))
   181  
   182  			session = helpers.CF("target")
   183  			Eventually(session).Should(Say(`org:\s+%s`, ReadOnlyOrg))
   184  			Eventually(session).Should(Say(`space:\s+%s`, ReadOnlySpace))
   185  			Eventually(session).Should(Exit(0))
   186  		})
   187  	})
   188  })