github.com/arunkumar7540/cli@v6.45.0+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/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-shared-domain command", func() {
    14  	When("--help flag is given", func() {
    15  		It("Displays command usage to output", func() {
    16  			session := helpers.CF("delete-shared-domain", "--help")
    17  
    18  			Eventually(session).Should(Say("NAME:"))
    19  			Eventually(session).Should(Say(`\s+delete-shared-domain - Delete a shared domain`))
    20  			Eventually(session).Should(Say("USAGE:"))
    21  			Eventually(session).Should(Say(`\s+cf delete-shared-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-private-domain, domains`))
    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-shared-domain", 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  				BeforeEach(func() {
    55  					_, err := buffer.Write([]byte("y\n"))
    56  					Expect(err).ToNot(HaveOccurred())
    57  				})
    58  
    59  				It("it asks for confirmation and deletes the domain", func() {
    60  					session := helpers.CFWithStdin(buffer, "delete-shared-domain", domainName)
    61  					Eventually(session).Should(Say("This action impacts all orgs using this domain."))
    62  					Eventually(session).Should(Say("Deleting the domain will remove associated routes which will make apps with this domain, in any org, unreachable."))
    63  					Eventually(session).Should(Say(`Really delete the shared domain %s\?`, domainName))
    64  					Eventually(session).Should(Say(regexp.QuoteMeta(`Deleting domain %s as %s...`), domainName, username))
    65  					Eventually(session).Should(Say("OK"))
    66  					Eventually(session).Should(Exit(0))
    67  				})
    68  			})
    69  
    70  			When("the user enters 'n'", func() {
    71  				BeforeEach(func() {
    72  					_, err := buffer.Write([]byte("n\n"))
    73  					Expect(err).ToNot(HaveOccurred())
    74  				})
    75  
    76  				It("it asks for confirmation and does not delete the domain", func() {
    77  					session := helpers.CFWithStdin(buffer, "delete-shared-domain", domainName)
    78  					Eventually(session).Should(Say("This action impacts all orgs using this domain."))
    79  					Eventually(session).Should(Say("Deleting the domain will remove associated routes which will make apps with this domain, in any org, unreachable."))
    80  					Eventually(session).Should(Say(`Really delete the shared domain %s\?`, domainName))
    81  					Eventually(session).Should(Say(`'%s' has not been deleted`, domainName))
    82  					Consistently(session).ShouldNot(Say("OK"))
    83  					Eventually(session).Should(Exit(0))
    84  				})
    85  			})
    86  		})
    87  
    88  		When("the -f flag is given", func() {
    89  			It("it deletes the domain without asking for confirmation", func() {
    90  				session := helpers.CFWithStdin(buffer, "delete-shared-domain", domainName, "-f")
    91  				Eventually(session).Should(Say(regexp.QuoteMeta(`Deleting domain %s as %s...`), domainName, username))
    92  				Consistently(session).ShouldNot(Say("Are you sure"))
    93  				Eventually(session).Should(Say("OK"))
    94  				Eventually(session).Should(Exit(0))
    95  			})
    96  		})
    97  	})
    98  })