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