github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+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("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-shared-domain, domains, unshare-private-domain`)) 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-private-domain", orgName, 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 var sharedDomainName string 62 BeforeEach(func() { 63 _, err := buffer.Write([]byte("y\n")) 64 Expect(err).ToNot(HaveOccurred()) 65 sharedDomainName = helpers.NewDomainName() 66 session := helpers.CF("create-shared-domain", sharedDomainName) 67 Eventually(session).Should(Exit(0)) 68 }) 69 When("the user attempts to delete-private-domain a private domain", func() { 70 It("it asks for confirmation and deletes the domain", func() { 71 session := helpers.CFWithStdin(buffer, "delete-private-domain", domainName) 72 Eventually(session).Should(Say("Deleting the private domain will remove associated routes which will make apps with this domain unreachable.")) 73 Eventually(session).Should(Say(`Really delete the private domain %s\?`, domainName)) 74 Eventually(session).Should(Say(regexp.QuoteMeta(`Deleting private domain %s as %s...`), domainName, username)) 75 Eventually(session).Should(Say("OK")) 76 Eventually(session).Should(Say("\n\nTIP: Run 'cf domains' to view available domains.")) 77 Eventually(session).Should(Exit(0)) 78 }) 79 }) 80 When("the user attempts to delete-private-domain a shared domain", func() { 81 It("it fails and provides the appropriate error message", func() { 82 session := helpers.CFWithStdin(buffer, "delete-private-domain", sharedDomainName) 83 Eventually(session).Should(Say("FAILED")) 84 Eventually(session.Err).Should(Say(`Domain '%s' is a shared domain, not a private domain.`, sharedDomainName)) 85 86 Eventually(session).Should(Exit(1)) 87 }) 88 }) 89 }) 90 91 When("the user enters 'n'", func() { 92 BeforeEach(func() { 93 _, err := buffer.Write([]byte("n\n")) 94 Expect(err).ToNot(HaveOccurred()) 95 }) 96 97 It("it asks for confirmation and does not delete the domain", func() { 98 session := helpers.CFWithStdin(buffer, "delete-private-domain", domainName) 99 Eventually(session).Should(Say("Deleting the private domain will remove associated routes which will make apps with this domain unreachable.")) 100 Eventually(session).Should(Say(`Really delete the private domain %s\?`, domainName)) 101 Eventually(session).Should(Say(`'%s' has not been deleted`, domainName)) 102 Consistently(session).ShouldNot(Say("OK")) 103 Eventually(session).Should(Exit(0)) 104 }) 105 }) 106 }) 107 108 When("the -f flag is given", func() { 109 It("it deletes the domain without asking for confirmation", func() { 110 session := helpers.CFWithStdin(buffer, "delete-private-domain", domainName, "-f") 111 Eventually(session).Should(Say(regexp.QuoteMeta(`Deleting private domain %s as %s...`), domainName, username)) 112 Consistently(session).ShouldNot(Say("Are you sure")) 113 Eventually(session).Should(Say("OK")) 114 Eventually(session).Should(Say("\n\nTIP: Run 'cf domains' to view available domains.")) 115 Eventually(session).Should(Exit(0)) 116 117 session = helpers.CF("domains") 118 Consistently(session).ShouldNot(Say(`%s\s+private`, domainName)) 119 Eventually(session).Should(Exit(0)) 120 }) 121 }) 122 123 When("the domain doesn't exist", func() { 124 It("displays OK and returns successfully", func() { 125 session := helpers.CFWithStdin(buffer, "delete-private-domain", "non-existent.com", "-f") 126 Eventually(session.Err).Should(Say(`Domain 'non-existent\.com' does not exist\.`)) 127 Eventually(session).Should(Say("OK")) 128 Eventually(session).Should(Exit(0)) 129 }) 130 131 }) 132 }) 133 })