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