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