github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v7/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/cf/util/testhelpers/matchers" 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("domains command", func() { 14 Describe("help", func() { 15 It("appears in cf help -a", func() { 16 session := helpers.CF("help", "-a") 17 Eventually(session).Should(Exit(0)) 18 Expect(session).To(HaveCommandInCategoryWithDescription("domains", "DOMAINS", "List domains in the target org")) 19 }) 20 21 When("--help flag is set", func() { 22 It("displays command usage to output", func() { 23 session := helpers.CF("domains", "--help") 24 Eventually(session).Should(Say("NAME:")) 25 Eventually(session).Should(Say(`\s+domains - List domains in the target org`)) 26 27 Eventually(session).Should(Say("USAGE:")) 28 Eventually(session).Should(Say(`\s+cf domains`)) 29 30 Eventually(session).Should(Say("EXAMPLES:")) 31 Eventually(session).Should(Say(`\s+cf domains`)) 32 Eventually(session).Should(Say(`\s+cf domains --labels 'environment in \(production,staging\),tier in \(backend\)'`)) 33 Eventually(session).Should(Say(`\s+cf domains --labels 'env=dev,!chargeback-code,tier in \(backend,worker\)'`)) 34 35 Eventually(session).Should(Say("OPTIONS:")) 36 Eventually(session).Should(Say(`--labels\s+Selector to filter domains by labels`)) 37 38 Eventually(session).Should(Say("SEE ALSO:")) 39 Eventually(session).Should(Say(`\s+create-private-domain, create-route, create-shared-domain, routes, set-label`)) 40 Eventually(session).Should(Exit(0)) 41 }) 42 }) 43 }) 44 45 When("user is not logged in", func() { 46 BeforeEach(func() { 47 helpers.LogoutCF() 48 }) 49 50 It("displays an error message and fails", func() { 51 session := helpers.CF("domains") 52 Eventually(session).Should(Say("FAILED")) 53 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' or 'cf login --sso' to log in.")) 54 Eventually(session).Should(Exit(1)) 55 }) 56 }) 57 58 When("a random argument is passed to the command", func() { 59 It("displays an error message and fails", func() { 60 session := helpers.CF("domains", "random-arg") 61 Eventually(session).Should(Say("FAILED")) 62 Eventually(session.Err).Should(Say(`Incorrect Usage: unexpected argument "random-arg"`)) 63 Eventually(session).Should(Say("NAME:")) 64 Eventually(session).Should(Say(`\s+domains - List domains in the target org`)) 65 Eventually(session).Should(Say("USAGE:")) 66 Eventually(session).Should(Say(`\s+cf domains`)) 67 Eventually(session).Should(Say("OPTIONS:")) 68 Eventually(session).Should(Say(`--labels\s+Selector to filter domains by labels`)) 69 Eventually(session).Should(Say("SEE ALSO:")) 70 Eventually(session).Should(Say(`\s+create-private-domain, create-route, create-shared-domain, routes`)) 71 Eventually(session).Should(Exit(1)) 72 }) 73 }) 74 75 When("logged in", func() { 76 var userName string 77 78 BeforeEach(func() { 79 userName, _ = helpers.GetCredentials() 80 }) 81 82 When("no org is targeted", func() { 83 BeforeEach(func() { 84 helpers.LoginCF() 85 }) 86 87 It("displays an error message and fails", func() { 88 session := helpers.CF("domains") 89 Eventually(session).Should(Say("FAILED")) 90 Eventually(session.Err).Should(Say(`No org targeted, use 'cf target -o ORG' to target an org.`)) 91 Eventually(session).Should(Exit(1)) 92 }) 93 }) 94 95 When("an org is targeted", func() { 96 var ( 97 orgName string 98 spaceName string 99 sharedDomain1 helpers.Domain 100 sharedDomain2 helpers.Domain 101 ) 102 103 BeforeEach(func() { 104 orgName = helpers.NewOrgName() 105 spaceName = helpers.NewSpaceName() 106 helpers.SetupCF(orgName, spaceName) 107 108 sharedDomain1 = helpers.NewDomain(orgName, helpers.NewDomainName("a")) 109 sharedDomain1.CreateShared() 110 111 sharedDomain2 = helpers.NewDomain(orgName, helpers.NewDomainName("b")) 112 sharedDomain2.CreateShared() 113 Eventually(helpers.CF("set-label", "domain", sharedDomain1.Name, "keyfor1=valuefor1")).Should(Exit(0)) 114 }) 115 AfterEach(func() { 116 Eventually(helpers.CF("delete-shared-domain", sharedDomain1.Name, "-f")).Should(Exit(0)) 117 Eventually(helpers.CF("delete-shared-domain", sharedDomain2.Name, "-f")).Should(Exit(0)) 118 Eventually(helpers.CF("delete-space", spaceName, "-f")).Should(Exit(0)) 119 Eventually(helpers.CF("delete-org", orgName, "-f")).Should(Exit(0)) 120 }) 121 122 When("the targeted org has shared domains", func() { 123 124 It("displays the shared domains and denotes that they are shared", func() { 125 session := helpers.CF("domains") 126 Eventually(session).Should(Exit(0)) 127 128 Expect(session).Should(Say(`Getting domains in org %s as %s\.\.\.`, orgName, userName)) 129 Expect(session).Should(Say(`name\s+availability\s+internal`)) 130 Expect(session).Should(Say(`%s\s+shared\s+`, sharedDomain1.Name)) 131 Expect(session).Should(Say(`%s\s+shared\s+`, sharedDomain2.Name)) 132 }) 133 134 It("displays the shared domains and denotes that they are shared for matching labels only", func() { 135 session := helpers.CF("domains", "--labels", "keyfor1=valuefor1") 136 Eventually(session).Should(Exit(0)) 137 138 Expect(session).Should(Say(`Getting domains in org %s as %s\.\.\.`, orgName, userName)) 139 Expect(session).Should(Say(`name\s+availability\s+internal`)) 140 Expect(session).Should(Say(`%s\s+shared\s+`, sharedDomain1.Name)) 141 Expect(session).ShouldNot(Say(`%s\s+shared\s+`, sharedDomain2.Name)) 142 }) 143 144 When("the shared domain is internal", func() { 145 var internalDomainName string 146 147 BeforeEach(func() { 148 helpers.SkipIfVersionLessThan(ccversion.MinVersionInternalDomainV2) 149 internalDomainName = helpers.NewDomainName() 150 internalDomain := helpers.NewDomain(orgName, internalDomainName) 151 internalDomain.CreateInternal() 152 }) 153 AfterEach(func() { 154 Eventually(helpers.CF("delete-shared-domain", internalDomainName, "-f")).Should(Exit(0)) 155 }) 156 157 It("displays the internal flag on the shared domain", func() { 158 session := helpers.CF("domains") 159 Eventually(session).Should(Exit(0)) 160 161 Expect(session).Should(Say(`Getting domains in org %s as %s`, orgName, userName)) 162 Expect(session).Should(Say(`name\s+availability\s+internal`)) 163 Expect(session).Should(Say(`%s\s+shared\s+true`, internalDomainName)) 164 }) 165 166 It("displays the shared domains and denotes that they are shared for matching labels only", func() { 167 session := helpers.CF("domains", "--labels", "keyfor1=valuefor1") 168 Eventually(session).Should(Exit(0)) 169 170 Expect(session).Should(Say(`Getting domains in org %s as %s\.\.\.`, orgName, userName)) 171 Expect(session).Should(Say(`name\s+availability\s+internal`)) 172 Expect(session).Should(Say(`%s\s+shared\s+`, sharedDomain1.Name)) 173 Expect(session).ShouldNot(Say(`%s\s+shared\s+`, sharedDomain2.Name)) 174 Expect(session).ShouldNot(Say(internalDomainName)) 175 176 }) 177 }) 178 }) 179 180 When("the targeted org has a private domain", func() { 181 var privateDomain1, privateDomain2 helpers.Domain 182 183 BeforeEach(func() { 184 privateDomain1 = helpers.NewDomain(orgName, helpers.NewDomainName("a")) 185 privateDomain1.Create() 186 187 privateDomain2 = helpers.NewDomain(orgName, helpers.NewDomainName("b")) 188 privateDomain2.Create() 189 190 Eventually(helpers.CF("set-label", "domain", privateDomain2.Name, "keyfor2=valuefor2")).Should(Exit(0)) 191 }) 192 AfterEach(func() { 193 Eventually(helpers.CF("delete-private-domain", privateDomain1.Name, "-f")).Should(Exit(0)) 194 Eventually(helpers.CF("delete-private-domain", privateDomain2.Name, "-f")).Should(Exit(0)) 195 }) 196 197 It("displays the private domains", func() { 198 session := helpers.CF("domains") 199 200 Eventually(session).Should(Exit(0)) 201 Expect(session).Should(Say(`Getting domains in org %s as %s`, orgName, userName)) 202 Expect(session).Should(Say(`name\s+availability\s+internal`)) 203 Expect(session).Should(Say(`%s\s+private\s+`, privateDomain1.Name)) 204 Expect(session).Should(Say(`%s\s+private\s+`, privateDomain2.Name)) 205 }) 206 207 It("filters private domains by label", func() { 208 session := helpers.CF("domains", "--labels", "keyfor2=valuefor2") 209 210 Eventually(session).Should(Exit(0)) 211 Expect(session).Should(Say(`Getting domains in org %s as %s`, orgName, userName)) 212 Expect(session).Should(Say(`name\s+availability\s+internal`)) 213 Expect(session).ShouldNot(Say(`%s\s+private\s+`, privateDomain1.Name)) 214 Expect(session).Should(Say(`%s\s+private\s+`, privateDomain2.Name)) 215 }) 216 217 When("targeting a different org", func() { 218 var ( 219 newOrgName string 220 newSpaceName string 221 privateDomain3 helpers.Domain 222 ) 223 224 BeforeEach(func() { 225 newOrgName = helpers.NewOrgName() 226 newSpaceName = helpers.NewSpaceName() 227 helpers.SetupCF(newOrgName, newSpaceName) 228 229 privateDomain3 = helpers.NewDomain(newOrgName, helpers.NewDomainName("c")) 230 privateDomain3.Create() 231 }) 232 AfterEach(func() { 233 Eventually(helpers.CF("delete-private-domain", privateDomain3.Name, "-f")).Should(Exit(0)) 234 Eventually(helpers.CF("delete-space", newSpaceName, "-f")).Should(Exit(0)) 235 Eventually(helpers.CF("delete-org", newOrgName, "-f")).Should(Exit(0)) 236 // Outer after-eaches require the initial org/space to be targetted 237 helpers.TargetOrgAndSpace(orgName, spaceName) 238 }) 239 240 It("should not display the private domains of other orgs", func() { 241 session := helpers.CF("domains") 242 243 Eventually(session).Should(Say(`Getting domains in org %s as %s`, newOrgName, userName)) 244 Eventually(session).Should(Say(`name\s+availability\s+internal`)) 245 246 Consistently(session).ShouldNot(Say(`%s`, privateDomain1.Name)) 247 Consistently(session).ShouldNot(Say(`%s`, privateDomain2.Name)) 248 249 Eventually(session).Should(Say(`%s\s+shared\s+`, sharedDomain1.Name)) 250 Eventually(session).Should(Say(`%s\s+shared\s+`, sharedDomain2.Name)) 251 Eventually(session).Should(Say(`%s\s+private\s+`, privateDomain3.Name)) 252 Eventually(session).Should(Exit(0)) 253 }) 254 }) 255 256 When("logged in as a user that cannot see private domains", func() { 257 var userName string 258 259 BeforeEach(func() { 260 userName = helpers.SwitchToOrgRole(orgName, "BillingManager") 261 helpers.TargetOrg(orgName) 262 }) 263 JustAfterEach(func() { 264 // waiting AfterEach blocks are designed to run in as admin 265 helpers.LoginCF() 266 helpers.TargetOrg(orgName) 267 }) 268 269 It("only prints the shared domains", func() { 270 session := helpers.CF("domains") 271 272 Eventually(session).Should(Say(`Getting domains in org %s as %s`, orgName, userName)) 273 Eventually(session).Should(Say(`name\s+availability\s+internal`)) 274 Eventually(session).Should(Say(`%s\s+shared\s+`, sharedDomain1.Name)) 275 Eventually(session).Should(Say(`%s\s+shared\s+`, sharedDomain2.Name)) 276 277 Consistently(session).ShouldNot(Say(privateDomain1.Name)) 278 Consistently(session).ShouldNot(Say(privateDomain2.Name)) 279 280 Eventually(session).Should(Exit(0)) 281 }) 282 }) 283 }) 284 }) 285 }) 286 })