github.com/arunkumar7540/cli@v6.45.0+incompatible/integration/v7/isolated/create_private_domain_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("create-private-domain command", func() {
    14  	Context("Help", func() {
    15  		It("displays the help information", func() {
    16  			session := helpers.CF("create-private-domain", "--help")
    17  			Eventually(session).Should(Say("NAME:\n"))
    18  			Eventually(session).Should(Say(regexp.QuoteMeta("create-private-domain - Create a private domain for a specific org")))
    19  			Eventually(session).Should(Say("USAGE:\n"))
    20  			Eventually(session).Should(Say(regexp.QuoteMeta("cf create-private-domain ORG DOMAIN")))
    21  			Eventually(session).Should(Say("SEE ALSO:\n"))
    22  			Eventually(session).Should(Say("create-shared-domain, domains, share-private-domain"))
    23  			Eventually(session).Should(Exit(0))
    24  		})
    25  	})
    26  
    27  	var (
    28  		orgName    string
    29  		spaceName  string
    30  		domainName string
    31  	)
    32  
    33  	BeforeEach(func() {
    34  		orgName = helpers.NewOrgName()
    35  		spaceName = helpers.NewSpaceName()
    36  		helpers.SetupCF(orgName, spaceName)
    37  		domainName = helpers.NewDomainName()
    38  	})
    39  
    40  	When("the incorrect number of flags is provided", func() {
    41  		It("errors and shows the help text", func() {
    42  			session := helpers.CF("create-private-domain", domainName)
    43  			Eventually(session.Err).Should(Say(`Incorrect Usage:`))
    44  			Eventually(session).Should(Say("NAME:\n"))
    45  			Eventually(session).Should(Say(regexp.QuoteMeta("create-private-domain - Create a private domain for a specific org")))
    46  			Eventually(session).Should(Say("USAGE:\n"))
    47  			Eventually(session).Should(Say(regexp.QuoteMeta("cf create-private-domain ORG DOMAIN")))
    48  			Eventually(session).Should(Say("SEE ALSO:\n"))
    49  			Eventually(session).Should(Say("create-shared-domain, domains, share-private-domain"))
    50  			Eventually(session).Should(Exit(1))
    51  		})
    52  
    53  	})
    54  
    55  	When("user is logged in", func() {
    56  		When("org exists", func() {
    57  			When("domain name is valid", func() {
    58  				It("should create the private domain", func() {
    59  					session := helpers.CF("create-private-domain", orgName, domainName)
    60  
    61  					Eventually(session).Should(Say("Creating private domain %s for org %s as admin...", domainName, orgName))
    62  					Eventually(session).Should(Say("OK"))
    63  					Eventually(session).Should(Say("TIP: Domain '%s' is a private domain. Run 'cf share-private-domain' to share this domain with a different org.", domainName))
    64  					Eventually(session).Should(Exit(0))
    65  
    66  					session = helpers.CF("domains")
    67  					Eventually(session).Should(Say(`%s\s+private`, domainName))
    68  					Eventually(session).Should(Exit(0))
    69  				})
    70  			})
    71  
    72  			When("domain name is invalid", func() {
    73  				When("invalid format", func() {
    74  					BeforeEach(func() {
    75  						domainName = "invalid-domain-name%*$$#)*" + helpers.RandomName()
    76  					})
    77  
    78  					It("should fail and return an error", func() {
    79  						session := helpers.CF("create-private-domain", orgName, domainName)
    80  
    81  						Eventually(session).Should(Say("Creating private domain %s for org %s as admin...", regexp.QuoteMeta(domainName), orgName))
    82  						Eventually(session.Err).Should(Say("RFC 1035"))
    83  						Eventually(session).Should(Say("FAILED"))
    84  						Eventually(session).Should(Exit(1))
    85  					})
    86  				})
    87  
    88  				When("pre-existing domain", func() {
    89  					var privateDomain1 helpers.Domain
    90  					BeforeEach(func() {
    91  						privateDomain1 = helpers.NewDomain(orgName, helpers.NewDomainName())
    92  						privateDomain1.Create()
    93  					})
    94  					It("should fail and return an error", func() {
    95  						session := helpers.CF("create-private-domain", orgName, privateDomain1.Name)
    96  
    97  						Eventually(session.Err).Should(Say("The domain name \"%s\" is already in use", privateDomain1.Name))
    98  						Eventually(session).Should(Say("FAILED"))
    99  						Eventually(session).Should(Exit(1))
   100  					})
   101  				})
   102  			})
   103  		})
   104  	})
   105  
   106  	When("user is not logged in", func() {
   107  		BeforeEach(func() {
   108  			helpers.LogoutCF()
   109  		})
   110  
   111  		It("displays an error message and fails", func() {
   112  			session := helpers.CF("domains")
   113  			Eventually(session).Should(Say("FAILED"))
   114  			Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in."))
   115  			Eventually(session).Should(Exit(1))
   116  		})
   117  	})
   118  })