github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/delete_private_domain_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"regexp"
     5  
     6  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
     7  	"code.cloudfoundry.org/cli/integration/helpers"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  	. "github.com/onsi/gomega/gbytes"
    11  	. "github.com/onsi/gomega/gexec"
    12  )
    13  
    14  var _ = Describe("delete-private-domain command", func() {
    15  	Context("Help", func() {
    16  		It("appears in cf help -a", func() {
    17  			session := helpers.CF("help", "-a")
    18  			Eventually(session).Should(Exit(0))
    19  			Expect(session).To(HaveCommandInCategoryWithDescription("delete-private-domain", "DOMAINS", "Delete a private domain"))
    20  		})
    21  
    22  		It("Displays command usage to output", func() {
    23  			session := helpers.CF("delete-private-domain", "--help")
    24  
    25  			Eventually(session).Should(Say("NAME:"))
    26  			Eventually(session).Should(Say(`\s+delete-private-domain - Delete a private domain`))
    27  			Eventually(session).Should(Say("USAGE:"))
    28  			Eventually(session).Should(Say(`\s+cf delete-private-domain DOMAIN \[-f\]`))
    29  			Eventually(session).Should(Say("ALIAS:"))
    30  			Eventually(session).Should(Say(`\s+delete-domain`))
    31  			Eventually(session).Should(Say("OPTIONS:"))
    32  			Eventually(session).Should(Say(`\s+-f\s+Force deletion without confirmation`))
    33  			Eventually(session).Should(Say("SEE ALSO:"))
    34  			Eventually(session).Should(Say(`\s+delete-shared-domain, domains, unshare-private-domain`))
    35  			Eventually(session).Should(Exit(0))
    36  		})
    37  	})
    38  
    39  	When("the environment is set up correctly", func() {
    40  		var (
    41  			buffer     *Buffer
    42  			orgName    string
    43  			spaceName  string
    44  			domainName string
    45  			username   string
    46  		)
    47  
    48  		BeforeEach(func() {
    49  			buffer = NewBuffer()
    50  			domainName = helpers.NewDomainName()
    51  			orgName = helpers.NewOrgName()
    52  			spaceName = helpers.NewSpaceName()
    53  
    54  			username, _ = helpers.GetCredentials()
    55  			helpers.SetupCF(orgName, spaceName)
    56  
    57  			session := helpers.CF("create-private-domain", orgName, domainName)
    58  			Eventually(session).Should(Exit(0))
    59  		})
    60  
    61  		When("the -f flag is not given", func() {
    62  			When("the user enters 'y'", func() {
    63  				var sharedDomainName string
    64  				BeforeEach(func() {
    65  					_, err := buffer.Write([]byte("y\n"))
    66  					Expect(err).ToNot(HaveOccurred())
    67  					sharedDomainName = helpers.NewDomainName()
    68  					session := helpers.CF("create-shared-domain", sharedDomainName)
    69  					Eventually(session).Should(Exit(0))
    70  				})
    71  				When("the user attempts to delete-private-domain a private domain", func() {
    72  					It("it asks for confirmation and deletes the domain", func() {
    73  						session := helpers.CFWithStdin(buffer, "delete-private-domain", domainName)
    74  						Eventually(session).Should(Say("Deleting the private domain will remove associated routes which will make apps with this domain unreachable."))
    75  						Eventually(session).Should(Say(`Really delete the private domain %s\?`, domainName))
    76  						Eventually(session).Should(Say(regexp.QuoteMeta(`Deleting private domain %s as %s...`), domainName, username))
    77  						Eventually(session).Should(Say("OK"))
    78  						Eventually(session).Should(Say("\n\nTIP: Run 'cf domains' to view available domains."))
    79  						Eventually(session).Should(Exit(0))
    80  					})
    81  				})
    82  				When("the user attempts to delete-private-domain a shared domain", func() {
    83  					It("it fails and provides the appropriate error message", func() {
    84  						session := helpers.CFWithStdin(buffer, "delete-private-domain", sharedDomainName)
    85  						Eventually(session).Should(Say("FAILED"))
    86  						Eventually(session.Err).Should(Say(`Domain '%s' is a shared domain, not a private domain.`, sharedDomainName))
    87  
    88  						Eventually(session).Should(Exit(1))
    89  					})
    90  				})
    91  			})
    92  
    93  			When("the user enters 'n'", func() {
    94  				BeforeEach(func() {
    95  					_, err := buffer.Write([]byte("n\n"))
    96  					Expect(err).ToNot(HaveOccurred())
    97  				})
    98  
    99  				It("it asks for confirmation and does not delete the domain", func() {
   100  					session := helpers.CFWithStdin(buffer, "delete-private-domain", domainName)
   101  					Eventually(session).Should(Say("Deleting the private domain will remove associated routes which will make apps with this domain unreachable."))
   102  					Eventually(session).Should(Say(`Really delete the private domain %s\?`, domainName))
   103  					Eventually(session).Should(Say(`'%s' has not been deleted`, domainName))
   104  					Consistently(session).ShouldNot(Say("OK"))
   105  					Eventually(session).Should(Exit(0))
   106  				})
   107  			})
   108  		})
   109  
   110  		When("the -f flag is given", func() {
   111  			It("it deletes the domain without asking for confirmation", func() {
   112  				session := helpers.CFWithStdin(buffer, "delete-private-domain", domainName, "-f")
   113  				Eventually(session).Should(Say(regexp.QuoteMeta(`Deleting private domain %s as %s...`), domainName, username))
   114  				Consistently(session).ShouldNot(Say("Are you sure"))
   115  				Eventually(session).Should(Say("OK"))
   116  				Eventually(session).Should(Say("\n\nTIP: Run 'cf domains' to view available domains."))
   117  				Eventually(session).Should(Exit(0))
   118  
   119  				session = helpers.CF("domains")
   120  				Consistently(session).ShouldNot(Say(`%s\s+private`, domainName))
   121  				Eventually(session).Should(Exit(0))
   122  			})
   123  		})
   124  
   125  		When("the domain doesn't exist", func() {
   126  			It("displays OK and returns successfully", func() {
   127  				session := helpers.CFWithStdin(buffer, "delete-private-domain", "non-existent.com", "-f")
   128  				Eventually(session.Err).Should(Say(`Domain 'non-existent\.com' does not exist\.`))
   129  				Eventually(session).Should(Say("OK"))
   130  				Eventually(session).Should(Exit(0))
   131  			})
   132  
   133  		})
   134  	})
   135  })