github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/actor/v7action/space_test.go (about) 1 package v7action_test 2 3 import ( 4 "errors" 5 6 "code.cloudfoundry.org/cli/actor/actionerror" 7 . "code.cloudfoundry.org/cli/actor/v7action" 8 "code.cloudfoundry.org/cli/actor/v7action/v7actionfakes" 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 10 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3" 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 ) 14 15 var _ = Describe("Space", func() { 16 var ( 17 actor *Actor 18 fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient 19 ) 20 21 BeforeEach(func() { 22 fakeCloudControllerClient = new(v7actionfakes.FakeCloudControllerClient) 23 fakeConfig := new(v7actionfakes.FakeConfig) 24 actor = NewActor(fakeCloudControllerClient, fakeConfig, nil, nil, nil) 25 }) 26 27 Describe("CreateSpace", func() { 28 var ( 29 space Space 30 warnings Warnings 31 executeErr error 32 ) 33 34 JustBeforeEach(func() { 35 space, warnings, executeErr = actor.CreateSpace("space-name", "org-guid") 36 }) 37 38 When("the API layer calls are successful", func() { 39 BeforeEach(func() { 40 fakeCloudControllerClient.CreateSpaceReturns( 41 ccv3.Space{GUID: "space-guid", Name: "space-name"}, 42 ccv3.Warnings{"not-fatal-warning"}, 43 nil) 44 }) 45 46 It("creates a space successfully", func() { 47 Expect(executeErr).ToNot(HaveOccurred()) 48 Expect(space.Name).To(Equal("space-name")) 49 Expect(space.GUID).To(Equal("space-guid")) 50 Expect(warnings).To(ConsistOf("not-fatal-warning")) 51 }) 52 }) 53 54 When("the cc client returns an NameNotUniqueInOrgError", func() { 55 BeforeEach(func() { 56 fakeCloudControllerClient.CreateSpaceReturns( 57 ccv3.Space{}, 58 ccv3.Warnings{"create-space-warning"}, 59 ccerror.NameNotUniqueInOrgError{}, 60 ) 61 }) 62 63 It("returns the SpaceAlreadyExistsError and warnings", func() { 64 Expect(executeErr).To(MatchError(actionerror.SpaceAlreadyExistsError{ 65 Space: "space-name", 66 })) 67 Expect(warnings).To(ConsistOf("create-space-warning")) 68 }) 69 }) 70 71 When("the cc client returns a different error", func() { 72 BeforeEach(func() { 73 fakeCloudControllerClient.CreateSpaceReturns( 74 ccv3.Space{}, 75 ccv3.Warnings{"warning"}, 76 errors.New("api-error"), 77 ) 78 }) 79 80 It("it returns an error and prints warnings", func() { 81 Expect(warnings).To(ConsistOf("warning")) 82 Expect(executeErr).To(MatchError("api-error")) 83 84 Expect(fakeCloudControllerClient.CreateSpaceCallCount()).To(Equal(1)) 85 }) 86 }) 87 }) 88 89 Describe("ResetSpaceIsolationSegment", func() { 90 When("the organization does not have a default isolation segment", func() { 91 BeforeEach(func() { 92 fakeCloudControllerClient.UpdateSpaceIsolationSegmentRelationshipReturns( 93 ccv3.Relationship{GUID: ""}, 94 ccv3.Warnings{"warning-1", "warning-2"}, nil) 95 }) 96 97 It("returns an empty isolation segment GUID", func() { 98 newIsolationSegmentName, warnings, err := actor.ResetSpaceIsolationSegment("some-org-guid", "some-space-guid") 99 100 Expect(err).ToNot(HaveOccurred()) 101 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 102 Expect(newIsolationSegmentName).To(BeEmpty()) 103 104 Expect(fakeCloudControllerClient.UpdateSpaceIsolationSegmentRelationshipCallCount()).To(Equal(1)) 105 spaceGUID, isolationSegmentGUID := fakeCloudControllerClient.UpdateSpaceIsolationSegmentRelationshipArgsForCall(0) 106 Expect(spaceGUID).To(Equal("some-space-guid")) 107 Expect(isolationSegmentGUID).To(BeEmpty()) 108 109 Expect(fakeCloudControllerClient.GetOrganizationDefaultIsolationSegmentCallCount()).To(Equal(1)) 110 orgGUID := fakeCloudControllerClient.GetOrganizationDefaultIsolationSegmentArgsForCall(0) 111 Expect(orgGUID).To(Equal("some-org-guid")) 112 113 Expect(fakeCloudControllerClient.GetIsolationSegmentCallCount()).To(Equal(0)) 114 }) 115 }) 116 117 When("the organization has a default isolation segment", func() { 118 BeforeEach(func() { 119 fakeCloudControllerClient.UpdateSpaceIsolationSegmentRelationshipReturns( 120 ccv3.Relationship{GUID: ""}, 121 ccv3.Warnings{"warning-1", "warning-2"}, nil) 122 fakeCloudControllerClient.GetOrganizationDefaultIsolationSegmentReturns( 123 ccv3.Relationship{GUID: "some-iso-guid"}, 124 ccv3.Warnings{"warning-3", "warning-4"}, nil) 125 fakeCloudControllerClient.GetIsolationSegmentReturns( 126 ccv3.IsolationSegment{Name: "some-iso-name"}, 127 ccv3.Warnings{"warning-5", "warning-6"}, nil) 128 }) 129 130 It("returns the org's isolation segment GUID", func() { 131 newIsolationSegmentName, warnings, err := actor.ResetSpaceIsolationSegment("some-org-guid", "some-space-guid") 132 133 Expect(fakeCloudControllerClient.UpdateSpaceIsolationSegmentRelationshipCallCount()).To(Equal(1)) 134 spaceGUID, isolationSegmentGUID := fakeCloudControllerClient.UpdateSpaceIsolationSegmentRelationshipArgsForCall(0) 135 Expect(spaceGUID).To(Equal("some-space-guid")) 136 Expect(isolationSegmentGUID).To(BeEmpty()) 137 138 Expect(fakeCloudControllerClient.GetOrganizationDefaultIsolationSegmentCallCount()).To(Equal(1)) 139 orgGUID := fakeCloudControllerClient.GetOrganizationDefaultIsolationSegmentArgsForCall(0) 140 Expect(orgGUID).To(Equal("some-org-guid")) 141 142 Expect(fakeCloudControllerClient.GetIsolationSegmentCallCount()).To(Equal(1)) 143 isoSegGUID := fakeCloudControllerClient.GetIsolationSegmentArgsForCall(0) 144 Expect(isoSegGUID).To(Equal("some-iso-guid")) 145 146 Expect(err).ToNot(HaveOccurred()) 147 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "warning-3", "warning-4", "warning-5", "warning-6")) 148 Expect(newIsolationSegmentName).To(Equal("some-iso-name")) 149 }) 150 }) 151 152 When("assigning the space returns an error", func() { 153 var expectedErr error 154 155 BeforeEach(func() { 156 expectedErr = errors.New("some error") 157 fakeCloudControllerClient.UpdateSpaceIsolationSegmentRelationshipReturns( 158 ccv3.Relationship{GUID: ""}, 159 ccv3.Warnings{"warning-1", "warning-2"}, expectedErr) 160 }) 161 162 It("returns warnings and the error", func() { 163 _, warnings, err := actor.ResetSpaceIsolationSegment("some-org-guid", "some-space-guid") 164 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 165 Expect(err).To(MatchError(expectedErr)) 166 }) 167 }) 168 169 When("getting the org's default isolation segments returns an error", func() { 170 var expectedErr error 171 172 BeforeEach(func() { 173 expectedErr = errors.New("some error") 174 fakeCloudControllerClient.UpdateSpaceIsolationSegmentRelationshipReturns( 175 ccv3.Relationship{GUID: ""}, 176 ccv3.Warnings{"warning-1", "warning-2"}, nil) 177 fakeCloudControllerClient.GetOrganizationDefaultIsolationSegmentReturns( 178 ccv3.Relationship{GUID: "some-iso-guid"}, 179 ccv3.Warnings{"warning-3", "warning-4"}, expectedErr) 180 }) 181 182 It("returns the warnings and an error", func() { 183 _, warnings, err := actor.ResetSpaceIsolationSegment("some-org-guid", "some-space-guid") 184 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "warning-3", "warning-4")) 185 Expect(err).To(MatchError(expectedErr)) 186 }) 187 }) 188 189 When("getting the isolation segment returns an error", func() { 190 var expectedErr error 191 192 BeforeEach(func() { 193 expectedErr = errors.New("some error") 194 fakeCloudControllerClient.UpdateSpaceIsolationSegmentRelationshipReturns( 195 ccv3.Relationship{GUID: ""}, 196 ccv3.Warnings{"warning-1", "warning-2"}, nil) 197 fakeCloudControllerClient.GetOrganizationDefaultIsolationSegmentReturns( 198 ccv3.Relationship{GUID: "some-iso-guid"}, 199 ccv3.Warnings{"warning-3", "warning-4"}, nil) 200 fakeCloudControllerClient.GetIsolationSegmentReturns( 201 ccv3.IsolationSegment{Name: "some-iso-name"}, 202 ccv3.Warnings{"warning-5", "warning-6"}, expectedErr) 203 }) 204 205 It("returns the warnings and an error", func() { 206 _, warnings, err := actor.ResetSpaceIsolationSegment("some-org-guid", "some-space-guid") 207 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "warning-3", "warning-4", "warning-5", "warning-6")) 208 Expect(err).To(MatchError(expectedErr)) 209 }) 210 }) 211 }) 212 213 Describe("GetSpaceByNameAndOrganization", func() { 214 var ( 215 spaceName string 216 orgGUID string 217 218 space Space 219 warnings Warnings 220 executeErr error 221 ) 222 223 BeforeEach(func() { 224 spaceName = "some-space" 225 orgGUID = "some-org-guid" 226 }) 227 228 JustBeforeEach(func() { 229 space, warnings, executeErr = actor.GetSpaceByNameAndOrganization(spaceName, orgGUID) 230 }) 231 232 When("the GetSpace call is successful", func() { 233 When("the cloud controller returns back one space", func() { 234 BeforeEach(func() { 235 fakeCloudControllerClient.GetSpacesReturns( 236 []ccv3.Space{{GUID: "some-space-guid", Name: spaceName}}, 237 ccv3.Warnings{"some-space-warning"}, nil) 238 }) 239 240 It("returns back the first space and warnings", func() { 241 Expect(executeErr).ToNot(HaveOccurred()) 242 243 Expect(space).To(Equal(Space{ 244 GUID: "some-space-guid", 245 Name: spaceName, 246 })) 247 Expect(warnings).To(ConsistOf("some-space-warning")) 248 249 Expect(fakeCloudControllerClient.GetSpacesCallCount()).To(Equal(1)) 250 Expect(fakeCloudControllerClient.GetSpacesArgsForCall(0)).To(ConsistOf( 251 ccv3.Query{Key: ccv3.NameFilter, Values: []string{spaceName}}, 252 ccv3.Query{Key: ccv3.OrganizationGUIDFilter, Values: []string{orgGUID}}, 253 )) 254 }) 255 }) 256 257 When("the cloud controller returns back no spaces", func() { 258 BeforeEach(func() { 259 fakeCloudControllerClient.GetSpacesReturns( 260 nil, ccv3.Warnings{"some-space-warning"}, nil) 261 }) 262 263 It("returns a SpaceNotFoundError and warnings", func() { 264 Expect(executeErr).To(MatchError(actionerror.SpaceNotFoundError{Name: spaceName})) 265 266 Expect(warnings).To(ConsistOf("some-space-warning")) 267 }) 268 }) 269 }) 270 271 When("the GetSpace call is unsuccessful", func() { 272 BeforeEach(func() { 273 fakeCloudControllerClient.GetSpacesReturns( 274 nil, 275 ccv3.Warnings{"some-space-warning"}, 276 errors.New("cannot get space")) 277 }) 278 279 It("returns an error and warnings", func() { 280 Expect(executeErr).To(MatchError("cannot get space")) 281 Expect(warnings).To(ConsistOf("some-space-warning")) 282 }) 283 }) 284 285 }) 286 287 Describe("GetOrganizationSpaces", func() { 288 When("there are spaces in the org", func() { 289 BeforeEach(func() { 290 fakeCloudControllerClient.GetSpacesReturns( 291 []ccv3.Space{ 292 { 293 GUID: "space-1-guid", 294 Name: "space-1", 295 }, 296 { 297 GUID: "space-2-guid", 298 Name: "space-2", 299 }, 300 }, 301 ccv3.Warnings{"warning-1", "warning-2"}, 302 nil) 303 }) 304 305 It("returns all spaces and all warnings", func() { 306 spaces, warnings, err := actor.GetOrganizationSpaces("some-org-guid") 307 308 Expect(err).ToNot(HaveOccurred()) 309 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 310 Expect(spaces).To(Equal( 311 []Space{ 312 { 313 GUID: "space-1-guid", 314 Name: "space-1", 315 }, 316 { 317 GUID: "space-2-guid", 318 Name: "space-2", 319 }, 320 })) 321 322 Expect(fakeCloudControllerClient.GetSpacesCallCount()).To(Equal(1)) 323 Expect(fakeCloudControllerClient.GetSpacesArgsForCall(0)).To(Equal( 324 []ccv3.Query{ 325 {Key: ccv3.OrganizationGUIDFilter, Values: []string{"some-org-guid"}}, 326 {Key: ccv3.OrderBy, Values: []string{ccv3.NameOrder}}, 327 })) 328 }) 329 330 When("a label selector is provided", func() { 331 332 It("passes the label selector through", func() { 333 _, _, err := actor.GetOrganizationSpacesWithLabelSelector("some-org-guid", "some-label-selector") 334 Expect(err).ToNot(HaveOccurred()) 335 336 Expect(fakeCloudControllerClient.GetSpacesCallCount()).To(Equal(1)) 337 338 expectedQuery := []ccv3.Query{ 339 {Key: ccv3.OrganizationGUIDFilter, Values: []string{"some-org-guid"}}, 340 {Key: ccv3.OrderBy, Values: []string{ccv3.NameOrder}}, 341 {Key: ccv3.LabelSelectorFilter, Values: []string{"some-label-selector"}}, 342 } 343 actualQuery := fakeCloudControllerClient.GetSpacesArgsForCall(0) 344 Expect(actualQuery).To(Equal(expectedQuery)) 345 }) 346 347 }) 348 }) 349 350 When("an error is encountered", func() { 351 var returnedErr error 352 353 BeforeEach(func() { 354 returnedErr = errors.New("cc-get-spaces-error") 355 fakeCloudControllerClient.GetSpacesReturns( 356 []ccv3.Space{}, 357 ccv3.Warnings{"warning-1", "warning-2"}, 358 returnedErr, 359 ) 360 }) 361 362 It("returns the error and all warnings", func() { 363 _, warnings, err := actor.GetOrganizationSpaces("some-org-guid") 364 365 Expect(err).To(MatchError(returnedErr)) 366 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 367 }) 368 }) 369 }) 370 371 Describe("DeleteSpaceByNameAndOrganizationName", func() { 372 var ( 373 warnings Warnings 374 err error 375 ) 376 377 JustBeforeEach(func() { 378 warnings, err = actor.DeleteSpaceByNameAndOrganizationName("some-space", "some-org") 379 }) 380 381 When("the org is not found", func() { 382 BeforeEach(func() { 383 fakeCloudControllerClient.GetOrganizationsReturns( 384 []ccv3.Organization{}, 385 ccv3.Warnings{ 386 "warning-1", 387 "warning-2", 388 }, 389 nil, 390 ) 391 }) 392 393 It("returns an OrganizationNotFoundError", func() { 394 Expect(err).To(MatchError(actionerror.OrganizationNotFoundError{Name: "some-org"})) 395 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 396 }) 397 }) 398 399 When("the org is found", func() { 400 BeforeEach(func() { 401 fakeCloudControllerClient.GetOrganizationsReturns( 402 []ccv3.Organization{{Name: "some-org", GUID: "some-org-guid"}}, 403 ccv3.Warnings{"warning-1", "warning-2"}, 404 nil, 405 ) 406 }) 407 408 When("the space is not found", func() { 409 BeforeEach(func() { 410 fakeCloudControllerClient.GetSpacesReturns( 411 []ccv3.Space{}, 412 ccv3.Warnings{"warning-3", "warning-4"}, 413 nil, 414 ) 415 }) 416 417 It("returns an SpaceNotFoundError", func() { 418 Expect(err).To(MatchError(actionerror.SpaceNotFoundError{Name: "some-space"})) 419 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "warning-3", "warning-4")) 420 }) 421 }) 422 423 When("the space is found", func() { 424 BeforeEach(func() { 425 fakeCloudControllerClient.GetSpacesReturns( 426 []ccv3.Space{{GUID: "some-space-guid"}}, 427 ccv3.Warnings{"warning-3", "warning-4"}, 428 nil, 429 ) 430 }) 431 432 When("the delete returns an error", func() { 433 var expectedErr error 434 435 BeforeEach(func() { 436 expectedErr = errors.New("some delete space error") 437 fakeCloudControllerClient.DeleteSpaceReturns( 438 ccv3.JobURL(""), 439 ccv3.Warnings{"warning-5", "warning-6"}, 440 expectedErr, 441 ) 442 }) 443 444 It("returns the error", func() { 445 Expect(err).To(Equal(expectedErr)) 446 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "warning-3", "warning-4", "warning-5", "warning-6")) 447 }) 448 }) 449 450 When("the delete returns a job", func() { 451 BeforeEach(func() { 452 fakeCloudControllerClient.DeleteSpaceReturns( 453 ccv3.JobURL("some-url"), 454 ccv3.Warnings{"warning-5", "warning-6"}, 455 nil, 456 ) 457 }) 458 459 When("polling errors", func() { 460 var expectedErr error 461 462 BeforeEach(func() { 463 expectedErr = errors.New("Never expected, by anyone") 464 fakeCloudControllerClient.PollJobReturns(ccv3.Warnings{"warning-7", "warning-8"}, expectedErr) 465 }) 466 467 It("returns the error", func() { 468 Expect(err).To(Equal(expectedErr)) 469 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "warning-3", "warning-4", "warning-5", "warning-6", "warning-7", "warning-8")) 470 }) 471 }) 472 473 When("the job is successful", func() { 474 BeforeEach(func() { 475 fakeCloudControllerClient.PollJobReturns(ccv3.Warnings{"warning-7", "warning-8"}, nil) 476 }) 477 478 It("returns warnings and no error", func() { 479 Expect(err).ToNot(HaveOccurred()) 480 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "warning-3", "warning-4", "warning-5", "warning-6", "warning-7", "warning-8")) 481 482 Expect(fakeCloudControllerClient.GetOrganizationsCallCount()).To(Equal(1)) 483 Expect(fakeCloudControllerClient.GetOrganizationsArgsForCall(0)).To(Equal([]ccv3.Query{{ 484 Key: ccv3.NameFilter, 485 Values: []string{"some-org"}, 486 }})) 487 488 Expect(fakeCloudControllerClient.GetSpacesCallCount()).To(Equal(1)) 489 Expect(fakeCloudControllerClient.GetSpacesArgsForCall(0)).To(Equal([]ccv3.Query{{ 490 Key: ccv3.NameFilter, 491 Values: []string{"some-space"}, 492 }, 493 { 494 Key: ccv3.OrganizationGUIDFilter, 495 Values: []string{"some-org-guid"}, 496 }, 497 })) 498 499 Expect(fakeCloudControllerClient.DeleteSpaceCallCount()).To(Equal(1)) 500 Expect(fakeCloudControllerClient.DeleteSpaceArgsForCall(0)).To(Equal("some-space-guid")) 501 502 Expect(fakeCloudControllerClient.PollJobCallCount()).To(Equal(1)) 503 Expect(fakeCloudControllerClient.PollJobArgsForCall(0)).To(Equal(ccv3.JobURL("some-url"))) 504 }) 505 }) 506 }) 507 }) 508 }) 509 }) 510 511 Describe("RenameSpaceByNameAndOrganizationGUID", func() { 512 var ( 513 oldSpaceName string 514 newSpaceName string 515 orgGUID string 516 517 space Space 518 warnings Warnings 519 executeErr error 520 ) 521 522 JustBeforeEach(func() { 523 space, warnings, executeErr = actor.RenameSpaceByNameAndOrganizationGUID( 524 oldSpaceName, 525 newSpaceName, 526 orgGUID, 527 ) 528 }) 529 530 It("delegate to the actor to get the space", func() { 531 // assert on the underlying client call because we dont have a fake actor 532 Expect(fakeCloudControllerClient.GetSpacesCallCount()).To(Equal(1)) 533 }) 534 535 When("getting the space fails", func() { 536 BeforeEach(func() { 537 fakeCloudControllerClient.GetSpacesReturns( 538 nil, 539 ccv3.Warnings{"get-space-warning"}, 540 errors.New("get-space-error"), 541 ) 542 }) 543 544 It("returns the error and warnings", func() { 545 Expect(executeErr).To(MatchError("get-space-error")) 546 Expect(warnings).To(ConsistOf("get-space-warning")) 547 }) 548 }) 549 550 When("getting the space succeeds", func() { 551 BeforeEach(func() { 552 fakeCloudControllerClient.GetSpacesReturns( 553 []ccv3.Space{{Name: oldSpaceName, GUID: "space-guid"}}, 554 ccv3.Warnings{"get-space-warning"}, 555 nil, 556 ) 557 }) 558 559 It("delegates to the client to update the space", func() { 560 Expect(fakeCloudControllerClient.GetSpacesCallCount()).To(Equal(1)) 561 Expect(fakeCloudControllerClient.UpdateSpaceCallCount()).To(Equal(1)) 562 Expect(fakeCloudControllerClient.UpdateSpaceArgsForCall(0)).To(Equal(ccv3.Space{ 563 GUID: "space-guid", 564 Name: newSpaceName, 565 })) 566 }) 567 568 When("updating the space fails", func() { 569 BeforeEach(func() { 570 fakeCloudControllerClient.UpdateSpaceReturns( 571 ccv3.Space{}, 572 ccv3.Warnings{"update-space-warning"}, 573 errors.New("update-space-error"), 574 ) 575 }) 576 577 It("returns an error and all warnings", func() { 578 Expect(executeErr).To(MatchError("update-space-error")) 579 Expect(warnings).To(ConsistOf("get-space-warning", "update-space-warning")) 580 }) 581 582 }) 583 584 When("updating the space succeeds", func() { 585 BeforeEach(func() { 586 fakeCloudControllerClient.UpdateSpaceReturns( 587 ccv3.Space{Name: newSpaceName, GUID: "space-guid"}, 588 ccv3.Warnings{"update-space-warning"}, 589 nil, 590 ) 591 }) 592 593 It("returns warnings and no error", func() { 594 Expect(executeErr).ToNot(HaveOccurred()) 595 Expect(warnings).To(ConsistOf("get-space-warning", "update-space-warning")) 596 Expect(space).To(Equal(Space{Name: newSpaceName, GUID: "space-guid"})) 597 }) 598 }) 599 }) 600 }) 601 602 Describe("GetSpaceSummaryByNameAndOrganization", func() { 603 var ( 604 spaceSummary SpaceSummary 605 warnings Warnings 606 err error 607 ) 608 609 JustBeforeEach(func() { 610 spaceSummary, warnings, err = actor.GetSpaceSummaryByNameAndOrganization("space-name", "org-guid") 611 }) 612 613 When("getting the organization succeeds", func() { 614 var org ccv3.Organization 615 616 BeforeEach(func() { 617 org = ccv3.Organization{ 618 GUID: "some-org-guid", 619 Name: "some-org-name", 620 } 621 622 w := ccv3.Warnings{"get-org-warning"} 623 fakeCloudControllerClient.GetOrganizationReturns(org, w, nil) 624 }) 625 626 When("getting the space succeeds", func() { 627 var ccv3Spaces []ccv3.Space 628 629 BeforeEach(func() { 630 ccv3Spaces = []ccv3.Space{ 631 { 632 GUID: "some-space-guid", 633 Name: "some-space-name", 634 }, 635 } 636 637 w := ccv3.Warnings{"get-space-warning"} 638 fakeCloudControllerClient.GetSpacesReturns(ccv3Spaces, w, nil) 639 }) 640 641 When("getting the space applications succeeds", func() { 642 var apps []ccv3.Application 643 644 BeforeEach(func() { 645 apps = []ccv3.Application{ 646 { 647 Name: "some-app-name-B", 648 GUID: "some-app-guid-B", 649 }, 650 { 651 Name: "some-app-name-A", 652 GUID: "some-app-guid-A", 653 }, 654 } 655 656 w := ccv3.Warnings{"get-apps-warning"} 657 fakeCloudControllerClient.GetApplicationsReturns(apps, w, nil) 658 }) 659 660 When("getting the service instances succeeds", func() { 661 BeforeEach(func() { 662 fakeCloudControllerClient.GetServiceInstancesReturns( 663 []ccv3.ServiceInstance{{Name: "instance-1"}, {Name: "instance-2"}}, 664 ccv3.Warnings{"get-services-warning"}, 665 nil, 666 ) 667 }) 668 669 It("returns a populated space summary with app names sorted alphabetically", func() { 670 expectedSpaceSummary := SpaceSummary{ 671 Name: ccv3Spaces[0].Name, 672 OrgName: org.Name, 673 Space: Space{ 674 Name: ccv3Spaces[0].Name, 675 GUID: ccv3Spaces[0].GUID, 676 }, 677 AppNames: []string{"some-app-name-A", "some-app-name-B"}, 678 ServiceInstanceNames: []string{"instance-1", "instance-2"}, 679 } 680 681 Expect(err).ToNot(HaveOccurred()) 682 Expect(spaceSummary).To(Equal(expectedSpaceSummary)) 683 }) 684 685 It("propagates all warnings", func() { 686 Expect(warnings).To(ConsistOf("get-apps-warning", "get-services-warning", "get-space-warning", "get-org-warning")) 687 }) 688 }) 689 690 When("getting the service instances fails", func() { 691 BeforeEach(func() { 692 fakeCloudControllerClient.GetServiceInstancesReturns( 693 []ccv3.ServiceInstance{}, 694 ccv3.Warnings{"get-services-warning"}, 695 errors.New("get-services-error"), 696 ) 697 }) 698 699 It("returns warnings and error", func() { 700 Expect(err).To(MatchError("get-services-error")) 701 Expect(warnings).To(ConsistOf("get-apps-warning", "get-services-warning", "get-space-warning", "get-org-warning")) 702 }) 703 }) 704 705 When("getting the space isolation segment returns no isolation segment relationship", func() { 706 BeforeEach(func() { 707 fakeCloudControllerClient.GetSpaceIsolationSegmentReturns( 708 ccv3.Relationship{}, 709 ccv3.Warnings{"get-space-iso-seg-warning"}, 710 nil, 711 ) 712 }) 713 714 When("getting the org default isolation segment returns an isolation segment relationship", func() { 715 BeforeEach(func() { 716 fakeCloudControllerClient.GetOrganizationDefaultIsolationSegmentReturns( 717 ccv3.Relationship{GUID: "org-default-iso-seg-guid"}, 718 ccv3.Warnings{"get-org-default-iso-seg-warning"}, 719 nil, 720 ) 721 fakeCloudControllerClient.GetIsolationSegmentReturns( 722 ccv3.IsolationSegment{GUID: "org-default-iso-seg-guid", Name: "org-default-iso-seg-name"}, 723 ccv3.Warnings{"get-iso-seg-warning"}, 724 nil, 725 ) 726 }) 727 728 It("returns a populated space summary with app names sorted alphabetically", func() { 729 expectedSpaceSummary := SpaceSummary{ 730 Name: ccv3Spaces[0].Name, 731 OrgName: org.Name, 732 Space: Space{ 733 Name: ccv3Spaces[0].Name, 734 GUID: ccv3Spaces[0].GUID, 735 }, 736 AppNames: []string{"some-app-name-A", "some-app-name-B"}, 737 ServiceInstanceNames: []string{}, 738 IsolationSegmentName: "org-default-iso-seg-name (org default)", 739 } 740 741 Expect(err).ToNot(HaveOccurred()) 742 Expect(spaceSummary).To(Equal(expectedSpaceSummary)) 743 }) 744 745 It("propagates all warnings", func() { 746 Expect(warnings).To(ConsistOf("get-apps-warning", "get-space-warning", "get-org-warning", "get-space-iso-seg-warning", "get-org-default-iso-seg-warning", "get-iso-seg-warning")) 747 }) 748 }) 749 750 When("getting the org default isolation segment returns no isolation segment relationship", func() { 751 BeforeEach(func() { 752 fakeCloudControllerClient.GetOrganizationDefaultIsolationSegmentReturns( 753 ccv3.Relationship{}, 754 ccv3.Warnings{"get-org-default-iso-seg-warning"}, 755 nil, 756 ) 757 }) 758 759 It("does not try to get the isolation segment", func() { 760 Expect(fakeCloudControllerClient.GetIsolationSegmentCallCount()).To(Equal(0)) 761 }) 762 763 It("returns a populated space summary with app names sorted alphabetically", func() { 764 expectedSpaceSummary := SpaceSummary{ 765 Name: ccv3Spaces[0].Name, 766 OrgName: org.Name, 767 Space: Space{ 768 Name: ccv3Spaces[0].Name, 769 GUID: ccv3Spaces[0].GUID, 770 }, 771 AppNames: []string{"some-app-name-A", "some-app-name-B"}, 772 ServiceInstanceNames: []string{}, 773 } 774 775 Expect(err).ToNot(HaveOccurred()) 776 Expect(spaceSummary).To(Equal(expectedSpaceSummary)) 777 }) 778 779 It("propagates all warnings", func() { 780 Expect(warnings).To(ConsistOf("get-apps-warning", "get-space-warning", "get-org-warning", "get-space-iso-seg-warning", "get-org-default-iso-seg-warning")) 781 }) 782 }) 783 784 When("getting the org default isolation segment fails", func() { 785 BeforeEach(func() { 786 fakeCloudControllerClient.GetOrganizationDefaultIsolationSegmentReturns( 787 ccv3.Relationship{}, 788 ccv3.Warnings{"get-org-default-iso-seg-warning"}, 789 errors.New("get-org-default-iso-seg-error"), 790 ) 791 }) 792 793 It("returns all warnings and error", func() { 794 Expect(err).To(MatchError("get-org-default-iso-seg-error")) 795 Expect(warnings).To(ConsistOf("get-apps-warning", "get-space-warning", "get-org-warning", "get-space-iso-seg-warning", "get-org-default-iso-seg-warning")) 796 }) 797 }) 798 }) 799 800 When("getting the space isolation segment returns an isolation segment relationship", func() { 801 BeforeEach(func() { 802 fakeCloudControllerClient.GetSpaceIsolationSegmentReturns( 803 ccv3.Relationship{GUID: "some-iso-seg-guid"}, 804 ccv3.Warnings{"get-space-iso-seg-warning"}, 805 nil, 806 ) 807 }) 808 809 When("getting the isolation segment succeeds", func() { 810 BeforeEach(func() { 811 fakeCloudControllerClient.GetIsolationSegmentReturns( 812 ccv3.IsolationSegment{GUID: "some-iso-seg-guid", Name: "some-iso-seg-name"}, 813 ccv3.Warnings{"get-iso-seg-warning"}, 814 nil, 815 ) 816 }) 817 818 It("returns a populated space summary with app names sorted alphabetically", func() { 819 expectedSpaceSummary := SpaceSummary{ 820 Name: ccv3Spaces[0].Name, 821 OrgName: org.Name, 822 Space: Space{ 823 Name: ccv3Spaces[0].Name, 824 GUID: ccv3Spaces[0].GUID, 825 }, 826 AppNames: []string{"some-app-name-A", "some-app-name-B"}, 827 ServiceInstanceNames: []string{}, 828 IsolationSegmentName: "some-iso-seg-name", 829 } 830 831 Expect(err).ToNot(HaveOccurred()) 832 Expect(spaceSummary).To(Equal(expectedSpaceSummary)) 833 }) 834 835 It("propagates all warnings", func() { 836 Expect(warnings).To(ConsistOf("get-apps-warning", "get-space-warning", "get-org-warning", "get-space-iso-seg-warning", "get-iso-seg-warning")) 837 }) 838 }) 839 840 When("getting the isolation segment fails", func() { 841 BeforeEach(func() { 842 fakeCloudControllerClient.GetIsolationSegmentReturns( 843 ccv3.IsolationSegment{}, 844 ccv3.Warnings{"get-iso-seg-warning"}, 845 errors.New("get-iso-seg-error"), 846 ) 847 }) 848 849 It("returns all warnings and the error", func() { 850 Expect(err).To(MatchError("get-iso-seg-error")) 851 Expect(warnings).To(ConsistOf("get-apps-warning", "get-space-warning", "get-org-warning", "get-space-iso-seg-warning", "get-iso-seg-warning")) 852 }) 853 }) 854 }) 855 856 When("getting the space isolation segment fails", func() { 857 BeforeEach(func() { 858 fakeCloudControllerClient.GetSpaceIsolationSegmentReturns( 859 ccv3.Relationship{}, 860 ccv3.Warnings{"get-space-iso-seg-warning"}, 861 errors.New("get-space-iso-seg-error"), 862 ) 863 }) 864 865 It("returns all warnings and the error", func() { 866 Expect(err).To(MatchError("get-space-iso-seg-error")) 867 Expect(warnings).To(ConsistOf("get-apps-warning", "get-space-warning", "get-org-warning", "get-space-iso-seg-warning")) 868 }) 869 }) 870 }) 871 872 When("getting the space applications fails", func() { 873 BeforeEach(func() { 874 e := errors.New("get-apps-error") 875 w := ccv3.Warnings{"get-apps-warning"} 876 fakeCloudControllerClient.GetApplicationsReturns([]ccv3.Application{}, w, e) 877 }) 878 879 It("returns all warnings and an error", func() { 880 Expect(err).To(MatchError("get-apps-error")) 881 Expect(warnings).To(ConsistOf("get-apps-warning", "get-space-warning", "get-org-warning")) 882 }) 883 }) 884 }) 885 886 When("getting the space fails", func() { 887 BeforeEach(func() { 888 e := errors.New("get-space-error") 889 w := ccv3.Warnings{"get-space-warning"} 890 fakeCloudControllerClient.GetSpacesReturns([]ccv3.Space{}, w, e) 891 }) 892 893 It("returns all warnings and an error", func() { 894 Expect(err).To(MatchError("get-space-error")) 895 Expect(warnings).To(ConsistOf("get-space-warning", "get-org-warning")) 896 }) 897 }) 898 }) 899 900 When("getting the organization fails", func() { 901 BeforeEach(func() { 902 e := errors.New("get-org-error") 903 w := ccv3.Warnings{"get-org-warning"} 904 fakeCloudControllerClient.GetOrganizationReturns(ccv3.Organization{}, w, e) 905 }) 906 907 It("returns warnings and an error", func() { 908 Expect(err).To(MatchError("get-org-error")) 909 Expect(warnings).To(ConsistOf("get-org-warning")) 910 }) 911 }) 912 }) 913 })