github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v6/isolated/domains_command_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 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("domains command", func() { 13 Describe("help", func() { 14 When("--help flag is set", func() { 15 It("displays command usage to output", func() { 16 session := helpers.CF("domains", "--help") 17 Eventually(session).Should(Say("NAME:")) 18 Eventually(session).Should(Say(`\s+domains - List domains in the target org`)) 19 Eventually(session).Should(Say("USAGE:")) 20 Eventually(session).Should(Say(`\s+cf domains`)) 21 Eventually(session).Should(Say("SEE ALSO:")) 22 Eventually(session).Should(Say(`\s+create-route, router-groups, routes`)) 23 Eventually(session).Should(Exit(0)) 24 }) 25 }) 26 }) 27 28 When("user is not logged in", func() { 29 BeforeEach(func() { 30 helpers.LogoutCF() 31 }) 32 33 It("displays an error message and fails", func() { 34 session := helpers.CF("domains") 35 Eventually(session).Should(Say("FAILED")) 36 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' or 'cf login --sso' to log in.")) 37 Eventually(session).Should(Exit(1)) 38 }) 39 }) 40 41 When("a random argument is passed to the command", func() { 42 It("displays an error message and fails", func() { 43 session := helpers.CF("domains", "random-arg") 44 Eventually(session).Should(Say("FAILED")) 45 Eventually(session.Err).Should(Say(`Incorrect Usage: unexpected argument "random-arg"`)) 46 Eventually(session).Should(Say("NAME:")) 47 Eventually(session).Should(Say(`\s+domains - List domains in the target org`)) 48 Eventually(session).Should(Say("USAGE:")) 49 Eventually(session).Should(Say(`\s+cf domains`)) 50 Eventually(session).Should(Exit(1)) 51 }) 52 }) 53 54 When("logged in as a privileged user", func() { 55 When("no org is targeted", func() { 56 BeforeEach(func() { 57 helpers.LoginCF() 58 }) 59 60 It("displays an error message and fails", func() { 61 session := helpers.CF("domains") 62 Eventually(session).Should(Say("FAILED")) 63 Eventually(session.Err).Should(Say(`No org targeted, use 'cf target -o ORG' to target an org.`)) 64 Eventually(session).Should(Exit(1)) 65 }) 66 }) 67 68 When("an org is targeted", func() { 69 var ( 70 username string 71 orgName string 72 sharedDomain1 helpers.Domain 73 sharedDomain2 helpers.Domain 74 ) 75 76 BeforeEach(func() { 77 username, _ = helpers.GetCredentials() 78 79 orgName = helpers.NewOrgName() 80 spaceName := helpers.NewSpaceName() 81 helpers.SetupCF(orgName, spaceName) 82 83 sharedDomain1 = helpers.NewDomain(orgName, helpers.NewDomainName()) 84 sharedDomain1.CreateShared() 85 86 sharedDomain2 = helpers.NewDomain(orgName, helpers.NewDomainName()) 87 sharedDomain2.CreateShared() 88 }) 89 90 When("the targeted org has shared domains", func() { 91 It("displays the shared domains and denotes that they are shared", func() { 92 session := helpers.CF("domains") 93 94 Eventually(session).Should(Say(`Getting domains in org %s as %s\.\.\.`, orgName, username)) 95 Eventually(session).Should(Say(`name\s+status\s+type\s+details`)) 96 Eventually(session).Should(Say(`%s\s+shared\s+`, sharedDomain1.Name)) 97 Eventually(session).Should(Say(`%s\s+shared\s+`, sharedDomain2.Name)) 98 Eventually(session).Should(Exit(0)) 99 }) 100 101 When("the shared domain has a type associated with it", func() { 102 var sharedDomainWithType helpers.Domain 103 104 BeforeEach(func() { 105 helpers.SkipIfNoRoutingAPI() 106 sharedDomainName := helpers.NewDomainName() 107 sharedDomainWithType = helpers.NewDomain(orgName, sharedDomainName) 108 routerGroupName := helpers.FindOrCreateTCPRouterGroup(GinkgoParallelNode()) 109 sharedDomainWithType.CreateWithRouterGroup(routerGroupName) 110 }) 111 112 It("displays the type of the shared domain", func() { 113 session := helpers.CF("domains") 114 115 Eventually(session).Should(Say(`Getting domains in org %s as %s`, orgName, username)) 116 Eventually(session).Should(Say(`name\s+status\s+type\s+details`)) 117 Eventually(session).Should(Say(`%s\s+shared\s+`, sharedDomain1.Name)) 118 Eventually(session).Should(Say(`%s\s+shared\s+`, sharedDomain2.Name)) 119 Eventually(session).Should(Say(`%s\s+shared\s+tcp`, sharedDomainWithType.Name)) 120 Eventually(session).Should(Exit(0)) 121 }) 122 }) 123 124 When("the shared domain is internal", func() { 125 var internalDomainName string 126 127 BeforeEach(func() { 128 helpers.SkipIfVersionLessThan(ccversion.MinVersionInternalDomainV2) 129 internalDomainName = helpers.NewDomainName() 130 internalDomain := helpers.NewDomain(orgName, internalDomainName) 131 internalDomain.CreateInternal() 132 }) 133 134 It("displays the internal flag on the shared domain", func() { 135 session := helpers.CF("domains") 136 137 Eventually(session).Should(Say(`Getting domains in org %s as %s`, orgName, username)) 138 Eventually(session).Should(Say(`name\s+status\s+type\s+details`)) 139 Eventually(session).Should(Say(`%s\s+shared\s+internal`, internalDomainName)) 140 Eventually(session).Should(Exit(0)) 141 }) 142 }) 143 }) 144 145 When("the targeted org has a private domain", func() { 146 var privateDomain1, privateDomain2 helpers.Domain 147 148 BeforeEach(func() { 149 privateDomain1 = helpers.NewDomain(orgName, helpers.NewDomainName()) 150 privateDomain1.Create() 151 152 privateDomain2 = helpers.NewDomain(orgName, helpers.NewDomainName()) 153 privateDomain2.Create() 154 }) 155 156 It("displays the private domains", func() { 157 session := helpers.CF("domains") 158 159 Eventually(session).Should(Say(`Getting domains in org %s as %s`, orgName, username)) 160 Eventually(session).Should(Say(`name\s+status\s+type\s+details`)) 161 Eventually(session).Should(Say(`%s\s+owned\s+`, privateDomain1.Name)) 162 Eventually(session).Should(Say(`%s\s+owned\s+`, privateDomain2.Name)) 163 Eventually(session).Should(Exit(0)) 164 }) 165 166 When("targeting a different org", func() { 167 var ( 168 newOrgName string 169 privateDomain3 helpers.Domain 170 ) 171 172 BeforeEach(func() { 173 newOrgName = helpers.NewOrgName() 174 newSpaceName := helpers.NewSpaceName() 175 helpers.SetupCF(newOrgName, newSpaceName) 176 177 privateDomain3 = helpers.NewDomain(newOrgName, helpers.NewDomainName()) 178 privateDomain3.Create() 179 }) 180 181 It("should not display the private domains of other orgs", func() { 182 session := helpers.CF("domains") 183 184 Eventually(session).Should(Say(`Getting domains in org %s as %s`, newOrgName, username)) 185 Eventually(session).Should(Say(`name\s+status\s+type\s+details`)) 186 187 Consistently(session).ShouldNot(Say(`%s`, privateDomain1.Name)) 188 Consistently(session).ShouldNot(Say(`%s`, privateDomain2.Name)) 189 190 Eventually(session).Should(Say(`%s\s+shared\s+`, sharedDomain1.Name)) 191 Eventually(session).Should(Say(`%s\s+shared\s+`, sharedDomain2.Name)) 192 Eventually(session).Should(Say(`%s\s+owned\s+`, privateDomain3.Name)) 193 Eventually(session).Should(Exit(0)) 194 }) 195 }) 196 197 When("logged in as a user that cannot see private domains", func() { 198 var username string 199 200 BeforeEach(func() { 201 username = helpers.SwitchToOrgRole(orgName, "BillingManager") 202 helpers.TargetOrg(orgName) 203 }) 204 205 It("only prints the shared domains", func() { 206 session := helpers.CF("domains") 207 208 Eventually(session).Should(Say(`Getting domains in org %s as %s`, orgName, username)) 209 Eventually(session).Should(Say(`name\s+status\s+type\s+details`)) 210 Eventually(session).Should(Say(`%s\s+shared\s+`, sharedDomain1.Name)) 211 Eventually(session).Should(Say(`%s\s+shared\s+`, sharedDomain2.Name)) 212 213 Consistently(session).ShouldNot(Say(privateDomain1.Name)) 214 Consistently(session).ShouldNot(Say(privateDomain2.Name)) 215 216 Eventually(session).Should(Exit(0)) 217 }) 218 }) 219 }) 220 }) 221 }) 222 })