github.com/cloudfoundry-community/cloudfoundry-cli@v6.44.1-0.20240130060226-cda5ed8e89a5+incompatible/integration/v7/isolated/unshare_private_domain_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/integration/helpers" 5 . "github.com/onsi/ginkgo" 6 . "github.com/onsi/gomega" 7 . "github.com/onsi/gomega/gbytes" 8 . "github.com/onsi/gomega/gexec" 9 ) 10 11 var _ = Describe("Unshare Private Domain", func() { 12 var ( 13 domainName string 14 owningOrgName string 15 sharedToOrgName string 16 ) 17 18 BeforeEach(func() { 19 domainName = helpers.NewDomainName() 20 sharedToOrgName = helpers.NewOrgName() 21 }) 22 23 Describe("Help Text", func() { 24 It("Displays the help text", func() { 25 session := helpers.CF("unshare-private-domain", "--help") 26 Eventually(session).Should(Say("NAME:")) 27 Eventually(session).Should(Say("unshare-private-domain - Unshare a private domain with a specific org")) 28 Eventually(session).Should(Say("USAGE:")) 29 Eventually(session).Should(Say("cf unshare-private-domain ORG DOMAIN")) 30 Eventually(session).Should(Say("SEE ALSO:")) 31 Eventually(session).Should(Say("delete-private-domain, domains")) 32 }) 33 }) 34 35 Describe("When the environment is not set up correctly", func() { 36 When("The user is not logged in", func() { 37 It("lets the user know", func() { 38 session := helpers.CF("unshare-private-domain", sharedToOrgName, domainName) 39 Eventually(session).Should(Say("FAILED")) 40 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in.")) 41 }) 42 }) 43 }) 44 45 Describe("When the environment is set up correctly", func() { 46 When("the user says yes", func() { 47 BeforeEach(func() { 48 helpers.LoginCF() 49 owningOrgName = helpers.CreateAndTargetOrg() 50 helpers.CreateOrg(sharedToOrgName) 51 domain := helpers.NewDomain(owningOrgName, domainName) 52 domain.CreatePrivate() 53 domain.V7Share(sharedToOrgName) 54 }) 55 56 It("unshares the domain from the org", func() { 57 buffer := NewBuffer() 58 _, err := buffer.Write([]byte("y\n")) 59 Expect(err).ToNot(HaveOccurred()) 60 session := helpers.CFWithStdin(buffer, "unshare-private-domain", sharedToOrgName, domainName) 61 Eventually(session).Should(Say(`Warning: org %s will no longer be able to access private domain %s`, sharedToOrgName, domainName)) 62 Eventually(session).Should(Say(`Really unshare private domain %s\? \[yN\]`, domainName)) 63 Eventually(session).Should(Say("Unsharing domain %s from org %s as admin...", domainName, sharedToOrgName)) 64 Eventually(session).Should(Say("OK")) 65 Eventually(session).Should(Exit(0)) 66 67 helpers.TargetOrg(sharedToOrgName) 68 session = helpers.CF("domains") 69 Consistently(session).Should(Not(Say("%s", domainName))) 70 }) 71 72 }) 73 When("the user says no", func() { 74 BeforeEach(func() { 75 helpers.LoginCF() 76 owningOrgName = helpers.CreateAndTargetOrg() 77 helpers.CreateOrg(sharedToOrgName) 78 domain := helpers.NewDomain(owningOrgName, domainName) 79 domain.CreatePrivate() 80 domain.V7Share(sharedToOrgName) 81 }) 82 83 It("does not unshare the domain from the org", func() { 84 buffer := NewBuffer() 85 _, err := buffer.Write([]byte("n\n")) 86 Expect(err).ToNot(HaveOccurred()) 87 session := helpers.CFWithStdin(buffer, "unshare-private-domain", sharedToOrgName, domainName) 88 Consistently(session).ShouldNot(Say("Unsharing domain %s from org %s as admin...", domainName, sharedToOrgName)) 89 Consistently(session).ShouldNot(Say("OK")) 90 Eventually(session).Should(Say(`Warning: org %s will no longer be able to access private domain %s`, sharedToOrgName, domainName)) 91 Eventually(session).Should(Say(`Really unshare private domain %s\? \[yN\]`, domainName)) 92 Eventually(session).Should(Say("Domain %s has not been unshared from organization %s", domainName, sharedToOrgName)) 93 Eventually(session).Should(Exit(0)) 94 95 helpers.TargetOrg(sharedToOrgName) 96 session = helpers.CF("domains") 97 Eventually(session).Should(Say("%s", domainName)) 98 }) 99 100 }) 101 }) 102 })