github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v7/isolated/create_shared_domain_test.go (about) 1 package isolated 2 3 import ( 4 "fmt" 5 "regexp" 6 7 . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" 8 "code.cloudfoundry.org/cli/integration/helpers" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/gbytes" 12 . "github.com/onsi/gomega/gexec" 13 ) 14 15 var _ = Describe("create-shared-domain command", func() { 16 Context("Help", func() { 17 It("appears in cf help -a", func() { 18 session := helpers.CF("help", "-a") 19 Eventually(session).Should(Exit(0)) 20 Expect(session).To(HaveCommandInCategoryWithDescription("create-shared-domain", "DOMAINS", "Create a domain that can be used by all orgs (admin-only)")) 21 }) 22 23 It("displays the help information", func() { 24 session := helpers.CF("create-shared-domain", "--help") 25 Eventually(session).Should(Say("NAME:\n")) 26 Eventually(session).Should(Say(regexp.QuoteMeta("create-shared-domain - Create a domain that can be used by all orgs (admin-only)"))) 27 Eventually(session).Should(Say("USAGE:\n")) 28 Eventually(session).Should(Say(regexp.QuoteMeta("cf create-shared-domain DOMAIN [--internal]"))) 29 Eventually(session).Should(Say("OPTIONS:\n")) 30 Eventually(session).Should(Say(`--internal\s+Applications that use internal routes communicate directly on the container network`)) 31 Eventually(session).Should(Say("SEE ALSO:\n")) 32 Eventually(session).Should(Say("create-private-domain, domains")) 33 Eventually(session).Should(Exit(0)) 34 }) 35 }) 36 37 var ( 38 orgName string 39 spaceName string 40 domainName string 41 ) 42 43 BeforeEach(func() { 44 orgName = helpers.NewOrgName() 45 spaceName = helpers.NewSpaceName() 46 helpers.SetupCF(orgName, spaceName) 47 domainName = helpers.NewDomainName() 48 }) 49 50 When("user is logged in", func() { 51 var userName string 52 53 BeforeEach(func() { 54 userName, _ = helpers.GetCredentials() 55 }) 56 57 When("No optional flags are specified", func() { 58 When("domain name is valid", func() { 59 It("should create the shared domain", func() { 60 session := helpers.CF("create-shared-domain", domainName) 61 62 Eventually(session).Should(Say("Creating shared domain %s as %s...", domainName, userName)) 63 Eventually(session).Should(Say("OK")) 64 Eventually(session).Should(Say("TIP: Domain '%s' is shared with all orgs. Run 'cf domains' to view available domains.", domainName)) 65 Eventually(session).Should(Exit(0)) 66 67 session = helpers.CF("domains") 68 Eventually(session).Should(Say(`%s\s+shared`, domainName)) 69 Eventually(session).Should(Exit(0)) 70 }) 71 }) 72 73 When("domain name is invalid", 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-shared-domain", domainName) 80 81 Eventually(session).Should(Say("Creating shared domain %s as %s...", regexp.QuoteMeta(domainName), userName)) 82 Eventually(session.Err).Should(Say("RFC 1035")) 83 Eventually(session).Should(Say("FAILED")) 84 Eventually(session).Should(Exit(1)) 85 }) 86 }) 87 }) 88 89 When("the --internal flag is specified", func() { 90 It("creates a domain with internal flag", func() { 91 session := helpers.CF("create-shared-domain", domainName, "--internal") 92 93 Eventually(session).Should(Say("Creating shared domain %s as %s...", domainName, userName)) 94 Eventually(session).Should(Say("OK")) 95 Eventually(session).Should(Exit(0)) 96 97 session = helpers.CF("domains") 98 Eventually(session).Should(Say(`%s\s+shared\s+true`, domainName)) 99 Eventually(session).Should(Exit(0)) 100 }) 101 }) 102 }) 103 104 When("user is logged in as another user", func() { 105 var ( 106 username string 107 password string 108 ) 109 110 BeforeEach(func() { 111 helpers.LoginCF() 112 username, password = helpers.CreateUser() 113 helpers.LogoutCF() 114 helpers.LoginAs(username, password) 115 }) 116 117 It("should not be able to create shared domain", func() { 118 session := helpers.CF("create-shared-domain", domainName) 119 Eventually(session).Should(Say(fmt.Sprintf("Creating shared domain %s as %s...", domainName, username))) 120 Eventually(session.Err).Should(Say("You are not authorized to perform the requested action")) 121 Eventually(session).Should(Say("FAILED")) 122 Eventually(session).Should(Exit(1)) 123 }) 124 }) 125 })