github.com/cloudfoundry/cli@v7.1.0+incompatible/actor/v7action/domain_test.go (about) 1 package v7action_test 2 3 import ( 4 "errors" 5 6 . "code.cloudfoundry.org/cli/actor/v7action" 7 "code.cloudfoundry.org/cli/actor/v7action/v7actionfakes" 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 9 "code.cloudfoundry.org/cli/api/router" 10 "code.cloudfoundry.org/cli/resources" 11 "code.cloudfoundry.org/cli/types" 12 . "github.com/onsi/ginkgo" 13 . "github.com/onsi/gomega" 14 ) 15 16 var _ = Describe("Domain Actions", func() { 17 var ( 18 actor *Actor 19 fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient 20 fakeRoutingClient *v7actionfakes.FakeRoutingClient 21 ) 22 23 BeforeEach(func() { 24 actor, fakeCloudControllerClient, _, _, _, fakeRoutingClient, _ = NewTestActor() 25 }) 26 27 Describe("CheckRoute", func() { 28 var ( 29 domainName string 30 hostname string 31 path string 32 port int 33 34 matches bool 35 warnings Warnings 36 executeErr error 37 ) 38 39 BeforeEach(func() { 40 domainName = "domain-name" 41 hostname = "host" 42 path = "/path" 43 44 fakeCloudControllerClient.GetDomainsReturns( 45 []resources.Domain{{GUID: "domain-guid"}}, 46 ccv3.Warnings{"get-domains-warning"}, 47 nil, 48 ) 49 50 fakeCloudControllerClient.CheckRouteReturns( 51 true, 52 ccv3.Warnings{"check-route-warning-1", "check-route-warning-2"}, 53 nil, 54 ) 55 }) 56 57 JustBeforeEach(func() { 58 matches, warnings, executeErr = actor.CheckRoute(domainName, hostname, path, port) 59 }) 60 61 It("delegates to the cloud controller client", func() { 62 Expect(fakeCloudControllerClient.GetDomainsCallCount()).To(Equal(1)) 63 givenQuery := fakeCloudControllerClient.GetDomainsArgsForCall(0) 64 Expect(givenQuery).To(Equal([]ccv3.Query{ 65 {Key: ccv3.NameFilter, Values: []string{domainName}}, 66 })) 67 68 Expect(fakeCloudControllerClient.CheckRouteCallCount()).To(Equal(1)) 69 givenDomainGUID, givenHostname, givenPath, givenPort := fakeCloudControllerClient.CheckRouteArgsForCall(0) 70 Expect(givenDomainGUID).To(Equal("domain-guid")) 71 Expect(givenHostname).To(Equal(hostname)) 72 Expect(givenPath).To(Equal(path)) 73 Expect(givenPort).To(Equal(0)) 74 75 Expect(matches).To(BeTrue()) 76 Expect(warnings).To(ConsistOf("get-domains-warning", "check-route-warning-1", "check-route-warning-2")) 77 Expect(executeErr).NotTo(HaveOccurred()) 78 }) 79 80 When("getting the domain by name errors", func() { 81 BeforeEach(func() { 82 fakeCloudControllerClient.GetDomainsReturns( 83 []resources.Domain{{GUID: "domain-guid"}}, 84 ccv3.Warnings{"get-domains-warning"}, 85 errors.New("domain not found"), 86 ) 87 }) 88 89 It("returns the error and any warnings", func() { 90 Expect(warnings).To(ConsistOf("get-domains-warning")) 91 Expect(executeErr).To(MatchError("domain not found")) 92 }) 93 }) 94 95 When("checking the route errors", func() { 96 BeforeEach(func() { 97 fakeCloudControllerClient.CheckRouteReturns( 98 true, 99 ccv3.Warnings{"check-route-warning-1", "check-route-warning-2"}, 100 errors.New("failed to check route"), 101 ) 102 }) 103 104 It("returns the error and any warnings", func() { 105 Expect(warnings).To(ConsistOf("get-domains-warning", "check-route-warning-1", "check-route-warning-2")) 106 Expect(executeErr).To(MatchError("failed to check route")) 107 }) 108 }) 109 }) 110 111 Describe("CreateSharedDomain", func() { 112 var ( 113 warnings Warnings 114 executeErr error 115 routerGroup string 116 ) 117 118 JustBeforeEach(func() { 119 warnings, executeErr = actor.CreateSharedDomain("the-domain-name", true, routerGroup) 120 }) 121 122 BeforeEach(func() { 123 routerGroup = "" 124 fakeCloudControllerClient.CreateDomainReturns(resources.Domain{}, ccv3.Warnings{"create-warning-1", "create-warning-2"}, errors.New("create-error")) 125 }) 126 127 It("delegates to the cloud controller client", func() { 128 Expect(executeErr).To(MatchError("create-error")) 129 Expect(warnings).To(ConsistOf("create-warning-1", "create-warning-2")) 130 131 Expect(fakeRoutingClient.GetRouterGroupsCallCount()).To(Equal(0)) 132 133 Expect(fakeCloudControllerClient.CreateDomainCallCount()).To(Equal(1)) 134 passedDomain := fakeCloudControllerClient.CreateDomainArgsForCall(0) 135 Expect(passedDomain).To(Equal( 136 resources.Domain{ 137 Name: "the-domain-name", 138 Internal: types.NullBool{IsSet: true, Value: true}, 139 RouterGroup: "", 140 }, 141 )) 142 }) 143 144 Context("when a router group name is provided", func() { 145 BeforeEach(func() { 146 routerGroup = "router-group" 147 fakeRoutingClient.GetRouterGroupByNameReturns( 148 router.RouterGroup{Name: routerGroup, GUID: "router-group-guid"}, nil, 149 ) 150 }) 151 152 It("delegates to the cloud controller client", func() { 153 Expect(executeErr).To(MatchError("create-error")) 154 Expect(warnings).To(ConsistOf("create-warning-1", "create-warning-2")) 155 156 Expect(fakeRoutingClient.GetRouterGroupByNameCallCount()).To(Equal(1)) 157 Expect(fakeRoutingClient.GetRouterGroupByNameArgsForCall(0)).To(Equal(routerGroup)) 158 159 Expect(fakeCloudControllerClient.CreateDomainCallCount()).To(Equal(1)) 160 passedDomain := fakeCloudControllerClient.CreateDomainArgsForCall(0) 161 162 Expect(passedDomain).To(Equal( 163 resources.Domain{ 164 Name: "the-domain-name", 165 Internal: types.NullBool{IsSet: true, Value: true}, 166 RouterGroup: "router-group-guid", 167 }, 168 )) 169 }) 170 }) 171 }) 172 173 Describe("CreatePrivateDomain", func() { 174 175 BeforeEach(func() { 176 fakeCloudControllerClient.GetOrganizationsReturns( 177 []resources.Organization{ 178 {GUID: "org-guid"}, 179 }, 180 ccv3.Warnings{"get-orgs-warning"}, 181 nil, 182 ) 183 184 fakeCloudControllerClient.CreateDomainReturns( 185 resources.Domain{}, 186 ccv3.Warnings{"create-warning-1", "create-warning-2"}, 187 errors.New("create-error"), 188 ) 189 }) 190 191 It("delegates to the cloud controller client", func() { 192 warnings, executeErr := actor.CreatePrivateDomain("private-domain-name", "org-name") 193 Expect(executeErr).To(MatchError("create-error")) 194 Expect(warnings).To(ConsistOf("get-orgs-warning", "create-warning-1", "create-warning-2")) 195 196 Expect(fakeCloudControllerClient.CreateDomainCallCount()).To(Equal(1)) 197 passedDomain := fakeCloudControllerClient.CreateDomainArgsForCall(0) 198 199 Expect(passedDomain).To(Equal( 200 resources.Domain{ 201 Name: "private-domain-name", 202 OrganizationGUID: "org-guid", 203 }, 204 )) 205 }) 206 }) 207 208 Describe("delete domain", func() { 209 var ( 210 domain resources.Domain 211 ) 212 BeforeEach(func() { 213 domain = resources.Domain{Name: "the-domain.com", GUID: "domain-guid"} 214 }) 215 216 It("delegates to the cloud controller client", func() { 217 fakeCloudControllerClient.DeleteDomainReturns( 218 ccv3.JobURL("https://jobs/job_guid"), 219 ccv3.Warnings{"delete-warning"}, 220 nil) 221 222 warnings, executeErr := actor.DeleteDomain(domain) 223 Expect(executeErr).ToNot(HaveOccurred()) 224 Expect(warnings).To(ConsistOf("delete-warning")) 225 226 Expect(fakeCloudControllerClient.DeleteDomainCallCount()).To(Equal(1)) 227 passedDomainGuid := fakeCloudControllerClient.DeleteDomainArgsForCall(0) 228 229 Expect(passedDomainGuid).To(Equal("domain-guid")) 230 231 Expect(fakeCloudControllerClient.PollJobCallCount()).To(Equal(1)) 232 responseJobUrl := fakeCloudControllerClient.PollJobArgsForCall(0) 233 Expect(responseJobUrl).To(Equal(ccv3.JobURL("https://jobs/job_guid"))) 234 }) 235 236 When("polling the job fails", func() { 237 BeforeEach(func() { 238 fakeCloudControllerClient.PollJobReturns( 239 ccv3.Warnings{"poll-job-warning"}, 240 errors.New("async-domain-delete-error"), 241 ) 242 }) 243 244 It("returns the error", func() { 245 warnings, err := actor.DeleteDomain(domain) 246 Expect(err).To(MatchError("async-domain-delete-error")) 247 Expect(warnings).To(ConsistOf( 248 "poll-job-warning", 249 )) 250 }) 251 }) 252 }) 253 254 Describe("list domains for org", func() { 255 var ( 256 ccv3Domains []resources.Domain 257 domains []resources.Domain 258 259 domain1Name string 260 domain1Guid string 261 262 domain2Name string 263 domain2Guid string 264 265 domain3Name string 266 domain3Guid string 267 268 org1Guid = "some-org-guid" 269 sharedFromOrgGuid = "another-org-guid" 270 warnings Warnings 271 executeErr error 272 labelSelector string 273 ) 274 275 BeforeEach(func() { 276 ccv3Domains = []resources.Domain{ 277 {Name: domain1Name, GUID: domain1Guid, OrganizationGUID: org1Guid}, 278 {Name: domain2Name, GUID: domain2Guid, OrganizationGUID: org1Guid}, 279 {Name: domain3Name, GUID: domain3Guid, OrganizationGUID: sharedFromOrgGuid}, 280 } 281 labelSelector = "foo=bar" 282 }) 283 284 JustBeforeEach(func() { 285 domains, warnings, executeErr = actor.GetOrganizationDomains(org1Guid, labelSelector) 286 }) 287 288 When("the API layer call is successful", func() { 289 expectedOrgGUID := "some-org-guid" 290 291 BeforeEach(func() { 292 fakeCloudControllerClient.GetOrganizationDomainsReturns( 293 ccv3Domains, 294 ccv3.Warnings{"some-domain-warning"}, 295 nil, 296 ) 297 }) 298 299 It("returns back the domains and warnings", func() { 300 Expect(executeErr).ToNot(HaveOccurred()) 301 302 Expect(fakeCloudControllerClient.GetOrganizationDomainsCallCount()).To(Equal(1)) 303 actualOrgGuid, _ := fakeCloudControllerClient.GetOrganizationDomainsArgsForCall(0) 304 Expect(actualOrgGuid).To(Equal(expectedOrgGUID)) 305 306 Expect(domains).To(ConsistOf( 307 resources.Domain{Name: domain1Name, GUID: domain1Guid, OrganizationGUID: org1Guid}, 308 resources.Domain{Name: domain2Name, GUID: domain2Guid, OrganizationGUID: org1Guid}, 309 resources.Domain{Name: domain3Name, GUID: domain3Guid, OrganizationGUID: sharedFromOrgGuid}, 310 )) 311 Expect(warnings).To(ConsistOf("some-domain-warning")) 312 313 }) 314 315 It("uses the label selector", func() { 316 _, actualQuery := fakeCloudControllerClient.GetOrganizationDomainsArgsForCall(0) 317 Expect(actualQuery).To(ContainElement(ccv3.Query{Key: ccv3.LabelSelectorFilter, Values: []string{"foo=bar"}})) 318 }) 319 320 When("the label selector isn't specified", func() { 321 BeforeEach(func() { 322 labelSelector = "" 323 }) 324 325 It("calls the API with no label selectors", func() { 326 Expect(executeErr).ToNot(HaveOccurred()) 327 328 Expect(fakeCloudControllerClient.GetOrganizationDomainsCallCount()).To(Equal(1)) 329 _, actualQuery := fakeCloudControllerClient.GetOrganizationDomainsArgsForCall(0) 330 Expect(len(actualQuery)).To(Equal(0)) 331 }) 332 }) 333 }) 334 335 When("when the API layer call returns an error", func() { 336 BeforeEach(func() { 337 fakeCloudControllerClient.GetOrganizationDomainsReturns( 338 []resources.Domain{}, 339 ccv3.Warnings{"some-domain-warning"}, 340 errors.New("list-error"), 341 ) 342 }) 343 344 It("returns the error and prints warnings", func() { 345 Expect(executeErr).To(MatchError("list-error")) 346 Expect(warnings).To(ConsistOf("some-domain-warning")) 347 Expect(domains).To(ConsistOf([]resources.Domain{})) 348 349 Expect(fakeCloudControllerClient.GetOrganizationDomainsCallCount()).To(Equal(1)) 350 }) 351 352 }) 353 }) 354 355 Describe("get domain by guid", func() { 356 var ( 357 domain resources.Domain 358 ccv3Domain resources.Domain 359 domain1Guid string 360 361 warnings Warnings 362 executeErr error 363 ) 364 365 BeforeEach(func() { 366 domain1Guid = "domain-1-guid" 367 ccv3Domain = resources.Domain{Name: "domain-1-name", GUID: domain1Guid} 368 }) 369 370 JustBeforeEach(func() { 371 372 domain, warnings, executeErr = actor.GetDomain(domain1Guid) 373 }) 374 375 When("the API layer call is successful", func() { 376 BeforeEach(func() { 377 fakeCloudControllerClient.GetDomainReturns( 378 ccv3Domain, 379 ccv3.Warnings{"some-domain-warning"}, 380 nil, 381 ) 382 }) 383 384 It("returns back the domains and warnings", func() { 385 Expect(executeErr).ToNot(HaveOccurred()) 386 387 Expect(fakeCloudControllerClient.GetDomainCallCount()).To(Equal(1)) 388 actualGUID := fakeCloudControllerClient.GetDomainArgsForCall(0) 389 Expect(actualGUID).To(Equal(domain1Guid)) 390 391 Expect(domain).To(Equal( 392 resources.Domain{Name: "domain-1-name", GUID: domain1Guid}, 393 )) 394 Expect(warnings).To(ConsistOf("some-domain-warning")) 395 396 }) 397 }) 398 399 When("when the API layer call returns an error", func() { 400 BeforeEach(func() { 401 fakeCloudControllerClient.GetDomainReturns( 402 resources.Domain{}, 403 ccv3.Warnings{"some-domain-warning"}, 404 errors.New("get-domain-error"), 405 ) 406 }) 407 408 It("returns the error and prints warnings", func() { 409 Expect(executeErr).To(MatchError("get-domain-error")) 410 Expect(warnings).To(ConsistOf("some-domain-warning")) 411 Expect(domain).To(Equal(resources.Domain{})) 412 413 Expect(fakeCloudControllerClient.GetDomainCallCount()).To(Equal(1)) 414 }) 415 }) 416 }) 417 418 Describe("get domain by name", func() { 419 var ( 420 ccv3Domains []resources.Domain 421 domain resources.Domain 422 423 domain1Name string 424 domain1Guid string 425 426 warnings Warnings 427 executeErr error 428 ) 429 430 BeforeEach(func() { 431 ccv3Domains = []resources.Domain{ 432 {Name: domain1Name, GUID: domain1Guid}, 433 } 434 }) 435 436 JustBeforeEach(func() { 437 domain, warnings, executeErr = actor.GetDomainByName(domain1Name) 438 }) 439 440 When("the API layer call is successful", func() { 441 expectedQuery := []ccv3.Query{{Key: ccv3.NameFilter, Values: []string{domain1Name}}} 442 BeforeEach(func() { 443 fakeCloudControllerClient.GetDomainsReturns( 444 ccv3Domains, 445 ccv3.Warnings{"some-domain-warning"}, 446 nil, 447 ) 448 }) 449 450 It("returns back the domains and warnings", func() { 451 Expect(executeErr).ToNot(HaveOccurred()) 452 453 Expect(fakeCloudControllerClient.GetDomainsCallCount()).To(Equal(1)) 454 actualQuery := fakeCloudControllerClient.GetDomainsArgsForCall(0) 455 Expect(actualQuery).To(Equal(expectedQuery)) 456 457 Expect(domain).To(Equal( 458 resources.Domain{Name: domain1Name, GUID: domain1Guid}, 459 )) 460 Expect(warnings).To(ConsistOf("some-domain-warning")) 461 462 }) 463 }) 464 465 When("when the API layer call returns an error", func() { 466 BeforeEach(func() { 467 fakeCloudControllerClient.GetDomainsReturns( 468 []resources.Domain{}, 469 ccv3.Warnings{"some-domain-warning"}, 470 errors.New("list-error"), 471 ) 472 }) 473 474 It("returns the error and prints warnings", func() { 475 Expect(executeErr).To(MatchError("list-error")) 476 Expect(warnings).To(ConsistOf("some-domain-warning")) 477 Expect(domain).To(Equal(resources.Domain{})) 478 479 Expect(fakeCloudControllerClient.GetDomainsCallCount()).To(Equal(1)) 480 }) 481 }) 482 }) 483 484 Describe("share private domain to org", func() { 485 BeforeEach(func() { 486 fakeCloudControllerClient.GetOrganizationsReturns( 487 []resources.Organization{ 488 {GUID: "org-guid"}, 489 }, 490 ccv3.Warnings{"get-orgs-warning"}, 491 nil, 492 ) 493 494 fakeCloudControllerClient.GetDomainsReturns( 495 []resources.Domain{ 496 {Name: "private-domain.com", GUID: "private-domain-guid"}, 497 }, 498 ccv3.Warnings{"get-domains-warning"}, 499 nil, 500 ) 501 502 fakeCloudControllerClient.SharePrivateDomainToOrgsReturns( 503 ccv3.Warnings{"share-domain-warning"}, 504 nil, 505 ) 506 }) 507 508 It("delegates to the cloud controller client", func() { 509 warnings, executeErr := actor.SharePrivateDomain("private-domain.com", "org-name") 510 Expect(executeErr).To(BeNil()) 511 Expect(warnings).To(ConsistOf("share-domain-warning", "get-orgs-warning", "get-domains-warning")) 512 513 Expect(fakeCloudControllerClient.GetDomainsCallCount()).To(Equal(1)) 514 actualQuery := fakeCloudControllerClient.GetDomainsArgsForCall(0) 515 Expect(actualQuery).To(Equal([]ccv3.Query{{Key: ccv3.NameFilter, Values: []string{"private-domain.com"}}})) 516 517 Expect(fakeCloudControllerClient.SharePrivateDomainToOrgsCallCount()).To(Equal(1)) 518 domainGuid, sharedOrgs := fakeCloudControllerClient.SharePrivateDomainToOrgsArgsForCall(0) 519 Expect(domainGuid).To(Equal("private-domain-guid")) 520 Expect(sharedOrgs).To(Equal(ccv3.SharedOrgs{GUIDs: []string{"org-guid"}})) 521 }) 522 }) 523 524 Describe("unshare private domain from org", func() { 525 var ( 526 domainName string 527 orgName string 528 executeErr error 529 warnings Warnings 530 ) 531 532 JustBeforeEach(func() { 533 warnings, executeErr = actor.UnsharePrivateDomain(domainName, orgName) 534 }) 535 536 When("getting the org or domain errors", func() { 537 BeforeEach(func() { 538 fakeCloudControllerClient.GetOrganizationsReturns( 539 nil, 540 ccv3.Warnings{"get-orgs-warning"}, 541 errors.New("get-orgs-error"), 542 ) 543 }) 544 It("returns an error and the warnings", func() { 545 Expect(fakeCloudControllerClient.UnsharePrivateDomainFromOrgCallCount()).To(Equal(0)) 546 547 Expect(executeErr).To(MatchError(errors.New("get-orgs-error"))) 548 Expect(warnings).To(ConsistOf("get-orgs-warning")) 549 }) 550 }) 551 552 When("getting the guids succeeds", func() { 553 BeforeEach(func() { 554 fakeCloudControllerClient.GetDomainsReturns( 555 []resources.Domain{ 556 {Name: domainName, GUID: "private-domain-guid"}, 557 }, 558 ccv3.Warnings{"get-domains-warning"}, 559 nil, 560 ) 561 562 fakeCloudControllerClient.GetOrganizationsReturns( 563 []resources.Organization{ 564 {Name: orgName, GUID: "org-guid"}, 565 }, 566 ccv3.Warnings{"get-orgs-warning"}, 567 nil, 568 ) 569 }) 570 571 When("Unsharing the domain errors", func() { 572 BeforeEach(func() { 573 fakeCloudControllerClient.UnsharePrivateDomainFromOrgReturns( 574 ccv3.Warnings{"unshare-domain-warning"}, 575 errors.New("unsahre-domain-error"), 576 ) 577 }) 578 579 It("returns any warnings and errors", func() { 580 Expect(fakeCloudControllerClient.UnsharePrivateDomainFromOrgCallCount()).To(Equal(1)) 581 actualDomainGUID, actualOrgGUID := fakeCloudControllerClient.UnsharePrivateDomainFromOrgArgsForCall(0) 582 Expect(actualDomainGUID).To(Equal("private-domain-guid")) 583 Expect(actualOrgGUID).To(Equal("org-guid")) 584 585 Expect(executeErr).To(MatchError(errors.New("unsahre-domain-error"))) 586 Expect(warnings).To(ConsistOf("get-orgs-warning", "get-domains-warning", "unshare-domain-warning")) 587 }) 588 }) 589 590 When("everything succeeds", func() { 591 BeforeEach(func() { 592 fakeCloudControllerClient.UnsharePrivateDomainFromOrgReturns( 593 ccv3.Warnings{"unshare-domain-warning"}, 594 nil, 595 ) 596 }) 597 598 It("returns any warnings and no error", func() { 599 Expect(fakeCloudControllerClient.UnsharePrivateDomainFromOrgCallCount()).To(Equal(1)) 600 actualDomainGUID, actualOrgGUID := fakeCloudControllerClient.UnsharePrivateDomainFromOrgArgsForCall(0) 601 Expect(actualDomainGUID).To(Equal("private-domain-guid")) 602 Expect(actualOrgGUID).To(Equal("org-guid")) 603 604 Expect(executeErr).ToNot(HaveOccurred()) 605 Expect(warnings).To(ConsistOf("get-orgs-warning", "get-domains-warning", "unshare-domain-warning")) 606 }) 607 }) 608 }) 609 }) 610 611 Describe("GetDomainAndOrgByNames", func() { 612 var ( 613 orgName = "my-org" 614 domainName = "domain.com" 615 616 orgGUID string 617 domainGUID string 618 warnings Warnings 619 executeErr error 620 ) 621 JustBeforeEach(func() { 622 orgGUID, domainGUID, warnings, executeErr = actor.GetDomainAndOrgGUIDsByName(domainName, orgName) 623 }) 624 625 When("Getting the organization is not successful", func() { 626 BeforeEach(func() { 627 fakeCloudControllerClient.GetOrganizationsReturns( 628 nil, 629 ccv3.Warnings{"get-orgs-warning"}, 630 errors.New("get-orgs-error"), 631 ) 632 }) 633 634 It("returns the error and doesnt get the domain", func() { 635 Expect(fakeCloudControllerClient.GetOrganizationsCallCount()).To(Equal(1)) 636 actualQuery := fakeCloudControllerClient.GetOrganizationsArgsForCall(0) 637 Expect(actualQuery).To(Equal([]ccv3.Query{{Key: ccv3.NameFilter, Values: []string{orgName}}})) 638 639 Expect(fakeCloudControllerClient.GetDomainsCallCount()).To(Equal(0)) 640 641 Expect(executeErr).To(MatchError(errors.New("get-orgs-error"))) 642 Expect(warnings).To(ConsistOf("get-orgs-warning")) 643 }) 644 }) 645 646 When("getting the orgs succeeds", func() { 647 BeforeEach(func() { 648 fakeCloudControllerClient.GetOrganizationsReturns( 649 []resources.Organization{ 650 {Name: orgName, GUID: "org-guid"}, 651 }, 652 ccv3.Warnings{"get-orgs-warning"}, 653 nil, 654 ) 655 }) 656 When("Getting the domain is not successful", func() { 657 BeforeEach(func() { 658 fakeCloudControllerClient.GetDomainsReturns( 659 nil, 660 ccv3.Warnings{"get-domains-warning"}, 661 errors.New("get-domains-error"), 662 ) 663 }) 664 665 It("returns the error and doesnt get the domain", func() { 666 Expect(fakeCloudControllerClient.GetOrganizationsCallCount()).To(Equal(1)) 667 actualQuery := fakeCloudControllerClient.GetOrganizationsArgsForCall(0) 668 Expect(actualQuery).To(Equal([]ccv3.Query{{Key: ccv3.NameFilter, Values: []string{orgName}}})) 669 670 Expect(fakeCloudControllerClient.GetDomainsCallCount()).To(Equal(1)) 671 actualQuery = fakeCloudControllerClient.GetDomainsArgsForCall(0) 672 Expect(actualQuery).To(Equal([]ccv3.Query{{Key: ccv3.NameFilter, Values: []string{domainName}}})) 673 674 Expect(executeErr).To(MatchError(errors.New("get-domains-error"))) 675 Expect(warnings).To(ConsistOf("get-orgs-warning", "get-domains-warning")) 676 }) 677 }) 678 679 When("the api call are successful", func() { 680 BeforeEach(func() { 681 fakeCloudControllerClient.GetDomainsReturns( 682 []resources.Domain{ 683 {Name: domainName, GUID: "private-domain-guid"}, 684 }, 685 ccv3.Warnings{"get-domains-warning"}, 686 nil, 687 ) 688 }) 689 690 It("returns the GUIDs", func() { 691 Expect(fakeCloudControllerClient.GetOrganizationsCallCount()).To(Equal(1)) 692 actualQuery := fakeCloudControllerClient.GetOrganizationsArgsForCall(0) 693 Expect(actualQuery).To(Equal([]ccv3.Query{{Key: ccv3.NameFilter, Values: []string{orgName}}})) 694 695 Expect(fakeCloudControllerClient.GetDomainsCallCount()).To(Equal(1)) 696 actualQuery = fakeCloudControllerClient.GetDomainsArgsForCall(0) 697 Expect(actualQuery).To(Equal([]ccv3.Query{{Key: ccv3.NameFilter, Values: []string{domainName}}})) 698 699 Expect(executeErr).ToNot(HaveOccurred()) 700 Expect(warnings).To(ConsistOf("get-orgs-warning", "get-domains-warning")) 701 Expect(orgGUID).To(Equal("org-guid")) 702 Expect(domainGUID).To(Equal("private-domain-guid")) 703 }) 704 }) 705 }) 706 }) 707 })