github.com/sleungcy/cli@v7.1.0+incompatible/integration/v7/isolated/unshare_private_domain_test.go (about)

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