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