github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v7/isolated/delete_shared_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-shared-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-shared-domain", "DOMAINS", "Delete a shared domain"))
    20  		})
    21  
    22  		It("Displays command usage to output", func() {
    23  			session := helpers.CF("delete-shared-domain", "--help")
    24  
    25  			Eventually(session).Should(Say("NAME:"))
    26  			Eventually(session).Should(Say(`\s+delete-shared-domain - Delete a shared domain`))
    27  			Eventually(session).Should(Say("USAGE:"))
    28  			Eventually(session).Should(Say(`\s+cf delete-shared-domain DOMAIN \[-f\]`))
    29  			Eventually(session).Should(Say("OPTIONS:"))
    30  			Eventually(session).Should(Say(`\s+-f\s+Force deletion without confirmation`))
    31  			Eventually(session).Should(Say("SEE ALSO:"))
    32  			Eventually(session).Should(Say(`\s+delete-private-domain, domains`))
    33  			Eventually(session).Should(Exit(0))
    34  		})
    35  	})
    36  
    37  	When("the environment is set up correctly", func() {
    38  		var (
    39  			buffer     *Buffer
    40  			orgName    string
    41  			spaceName  string
    42  			domainName string
    43  			username   string
    44  		)
    45  
    46  		BeforeEach(func() {
    47  			buffer = NewBuffer()
    48  			domainName = helpers.NewDomainName()
    49  			orgName = helpers.NewOrgName()
    50  			spaceName = helpers.NewSpaceName()
    51  
    52  			username, _ = helpers.GetCredentials()
    53  			helpers.SetupCF(orgName, spaceName)
    54  
    55  			session := helpers.CF("create-shared-domain", domainName)
    56  			Eventually(session).Should(Exit(0))
    57  		})
    58  
    59  		When("the -f flag is not given", func() {
    60  			When("the user enters 'y'", func() {
    61  				BeforeEach(func() {
    62  					_, err := buffer.Write([]byte("y\n"))
    63  					Expect(err).ToNot(HaveOccurred())
    64  				})
    65  
    66  				It("it asks for confirmation and deletes the domain", func() {
    67  					session := helpers.CFWithStdin(buffer, "delete-shared-domain", domainName)
    68  					Eventually(session).Should(Say("This action impacts all orgs using this domain."))
    69  					Eventually(session).Should(Say("Deleting the domain will remove associated routes which will make apps with this domain, in any org, unreachable."))
    70  					Eventually(session).Should(Say(`Really delete the shared domain %s\?`, domainName))
    71  					Eventually(session).Should(Say(regexp.QuoteMeta(`Deleting domain %s as %s...`), domainName, username))
    72  					Eventually(session).Should(Say("OK"))
    73  					Eventually(session).Should(Exit(0))
    74  				})
    75  			})
    76  
    77  			When("the user enters 'n'", func() {
    78  				BeforeEach(func() {
    79  					_, err := buffer.Write([]byte("n\n"))
    80  					Expect(err).ToNot(HaveOccurred())
    81  				})
    82  
    83  				It("it asks for confirmation and does not delete the domain", func() {
    84  					session := helpers.CFWithStdin(buffer, "delete-shared-domain", domainName)
    85  					Eventually(session).Should(Say("This action impacts all orgs using this domain."))
    86  					Eventually(session).Should(Say("Deleting the domain will remove associated routes which will make apps with this domain, in any org, unreachable."))
    87  					Eventually(session).Should(Say(`Really delete the shared domain %s\?`, domainName))
    88  					Eventually(session).Should(Say(`'%s' has not been deleted`, domainName))
    89  					Consistently(session).ShouldNot(Say("OK"))
    90  					Eventually(session).Should(Exit(0))
    91  				})
    92  			})
    93  		})
    94  
    95  		When("the -f flag is given", func() {
    96  			It("it deletes the domain without asking for confirmation", func() {
    97  				session := helpers.CFWithStdin(buffer, "delete-shared-domain", domainName, "-f")
    98  				Eventually(session).Should(Say(regexp.QuoteMeta(`Deleting domain %s as %s...`), domainName, username))
    99  				Consistently(session).ShouldNot(Say("Are you sure"))
   100  				Eventually(session).Should(Say("OK"))
   101  				Eventually(session).Should(Exit(0))
   102  
   103  				session = helpers.CF("domains")
   104  				Consistently(session).ShouldNot(Say(`%s\s+shared`, domainName))
   105  				Eventually(session).Should(Exit(0))
   106  			})
   107  		})
   108  	})
   109  })