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