github.com/lukasheimann/cloudfoundrycli@v7.1.0+incompatible/actor/v7action/isolation_segment_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/resources" 12 . "github.com/onsi/ginkgo" 13 . "github.com/onsi/gomega" 14 ) 15 16 var _ = Describe("Isolation Segment Actions", func() { 17 var ( 18 actor *Actor 19 fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient 20 ) 21 22 BeforeEach(func() { 23 fakeCloudControllerClient = new(v7actionfakes.FakeCloudControllerClient) 24 actor = NewActor(fakeCloudControllerClient, nil, nil, nil, nil, nil) 25 }) 26 27 Describe("CreateIsolationSegment", func() { 28 When("the create is successful", func() { 29 BeforeEach(func() { 30 fakeCloudControllerClient.CreateIsolationSegmentReturns( 31 ccv3.IsolationSegment{}, 32 ccv3.Warnings{"warning-1", "warning-2"}, 33 nil, 34 ) 35 }) 36 37 It("returns all warnings", func() { 38 warnings, err := actor.CreateIsolationSegmentByName(IsolationSegment{Name: "some-isolation-segment"}) 39 Expect(err).ToNot(HaveOccurred()) 40 41 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 42 43 Expect(fakeCloudControllerClient.CreateIsolationSegmentCallCount()).To(Equal(1)) 44 isolationSegmentName := fakeCloudControllerClient.CreateIsolationSegmentArgsForCall(0) 45 Expect(isolationSegmentName).To(Equal(ccv3.IsolationSegment{Name: "some-isolation-segment"})) 46 }) 47 }) 48 49 When("the cloud controller client returns an error", func() { 50 When("an unexpected error occurs", func() { 51 var expectedErr error 52 53 BeforeEach(func() { 54 expectedErr = errors.New("I am a CloudControllerClient Error") 55 fakeCloudControllerClient.CreateIsolationSegmentReturns( 56 ccv3.IsolationSegment{}, 57 ccv3.Warnings{"warning-1", "warning-2"}, 58 expectedErr, 59 ) 60 }) 61 62 It("returns the same error and all warnings", func() { 63 warnings, err := actor.CreateIsolationSegmentByName(IsolationSegment{Name: "some-isolation-segment"}) 64 Expect(err).To(MatchError(expectedErr)) 65 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 66 }) 67 }) 68 69 When("an UnprocessableEntityError occurs", func() { 70 BeforeEach(func() { 71 fakeCloudControllerClient.CreateIsolationSegmentReturns( 72 ccv3.IsolationSegment{}, 73 ccv3.Warnings{"warning-1", "warning-2"}, 74 ccerror.UnprocessableEntityError{}, 75 ) 76 }) 77 78 It("returns an IsolationSegmentAlreadyExistsError and all warnings", func() { 79 warnings, err := actor.CreateIsolationSegmentByName(IsolationSegment{Name: "some-isolation-segment"}) 80 Expect(err).To(MatchError(actionerror.IsolationSegmentAlreadyExistsError{Name: "some-isolation-segment"})) 81 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 82 }) 83 }) 84 }) 85 }) 86 87 Describe("DeleteIsolationSegmentByName", func() { 88 When("the isolation segment is found", func() { 89 BeforeEach(func() { 90 fakeCloudControllerClient.GetIsolationSegmentsReturns([]ccv3.IsolationSegment{ 91 { 92 GUID: "some-iso-guid", 93 Name: "some-iso-seg", 94 }, 95 }, ccv3.Warnings{"I r warnings", "I are two warnings"}, 96 nil, 97 ) 98 }) 99 100 When("the delete is successful", func() { 101 BeforeEach(func() { 102 fakeCloudControllerClient.DeleteIsolationSegmentReturns(ccv3.Warnings{"delete warning-1", "delete warning-2"}, nil) 103 }) 104 105 It("returns back all warnings", func() { 106 warnings, err := actor.DeleteIsolationSegmentByName("some-iso-seg") 107 Expect(err).NotTo(HaveOccurred()) 108 Expect(warnings).To(ConsistOf("I r warnings", "I are two warnings", "delete warning-1", "delete warning-2")) 109 110 Expect(fakeCloudControllerClient.GetIsolationSegmentsCallCount()).To(Equal(1)) 111 Expect(fakeCloudControllerClient.GetIsolationSegmentsArgsForCall(0)).To(ConsistOf( 112 ccv3.Query{Key: ccv3.NameFilter, Values: []string{"some-iso-seg"}}, 113 )) 114 115 Expect(fakeCloudControllerClient.DeleteIsolationSegmentCallCount()).To(Equal(1)) 116 Expect(fakeCloudControllerClient.DeleteIsolationSegmentArgsForCall(0)).To(Equal("some-iso-guid")) 117 }) 118 }) 119 120 When("the delete returns an error", func() { 121 var expectedErr error 122 123 BeforeEach(func() { 124 expectedErr = errors.New("some-cc-error") 125 fakeCloudControllerClient.DeleteIsolationSegmentReturns(ccv3.Warnings{"delete warning-1", "delete warning-2"}, expectedErr) 126 }) 127 128 It("returns back the error and all warnings", func() { 129 warnings, err := actor.DeleteIsolationSegmentByName("some-iso-seg") 130 Expect(warnings).To(ConsistOf("I r warnings", "I are two warnings", "delete warning-1", "delete warning-2")) 131 Expect(err).To(MatchError(expectedErr)) 132 }) 133 }) 134 }) 135 136 When("the search errors", func() { 137 var expectedErr error 138 139 BeforeEach(func() { 140 expectedErr = errors.New("some-cc-error") 141 fakeCloudControllerClient.GetIsolationSegmentsReturns(nil, ccv3.Warnings{"I r warnings", "I are two warnings"}, expectedErr) 142 }) 143 144 It("returns the error and all warnings", func() { 145 warnings, err := actor.DeleteIsolationSegmentByName("some-iso-seg") 146 Expect(warnings).To(ConsistOf("I r warnings", "I are two warnings")) 147 Expect(err).To(MatchError(expectedErr)) 148 }) 149 }) 150 }) 151 152 Describe("EntitleIsolationSegmentToOrganizationByName", func() { 153 When("the isolation segment exists", func() { 154 BeforeEach(func() { 155 fakeCloudControllerClient.GetIsolationSegmentsReturns([]ccv3.IsolationSegment{ 156 { 157 Name: "some-iso-seg", 158 GUID: "some-iso-guid", 159 }, 160 }, ccv3.Warnings{"get-iso-warning"}, nil) 161 }) 162 163 When("the organization exists", func() { 164 BeforeEach(func() { 165 fakeCloudControllerClient.GetOrganizationsReturns([]resources.Organization{ 166 { 167 Name: "some-org", 168 GUID: "some-org-guid", 169 }, 170 }, ccv3.Warnings{"get-org-warning"}, nil) 171 }) 172 173 When("the relationship succeeds", func() { 174 BeforeEach(func() { 175 fakeCloudControllerClient.EntitleIsolationSegmentToOrganizationsReturns( 176 resources.RelationshipList{GUIDs: []string{"some-relationship-guid"}}, 177 ccv3.Warnings{"entitle-iso-to-org-warning"}, 178 nil) 179 }) 180 181 It("returns all warnings", func() { 182 warnings, err := actor.EntitleIsolationSegmentToOrganizationByName("some-iso-seg", "some-org") 183 Expect(warnings).To(ConsistOf("get-iso-warning", "get-org-warning", "entitle-iso-to-org-warning")) 184 Expect(err).ToNot(HaveOccurred()) 185 Expect(fakeCloudControllerClient.GetOrganizationsCallCount()).To(Equal(1)) 186 Expect(fakeCloudControllerClient.GetIsolationSegmentsCallCount()).To(Equal(1)) 187 Expect(fakeCloudControllerClient.EntitleIsolationSegmentToOrganizationsCallCount()).To(Equal(1)) 188 }) 189 }) 190 191 When("the relationship fails", func() { 192 var expectedErr error 193 194 BeforeEach(func() { 195 expectedErr = errors.New("toxic-relationship") 196 fakeCloudControllerClient.EntitleIsolationSegmentToOrganizationsReturns( 197 resources.RelationshipList{}, 198 ccv3.Warnings{"entitle-iso-to-org-warning"}, 199 expectedErr) 200 }) 201 202 It("returns the error", func() { 203 warnings, err := actor.EntitleIsolationSegmentToOrganizationByName("some-iso-seg", "some-org") 204 Expect(warnings).To(ConsistOf("get-iso-warning", "get-org-warning", "entitle-iso-to-org-warning")) 205 Expect(err).To(MatchError(expectedErr)) 206 }) 207 208 }) 209 }) 210 211 When("retrieving the orgs errors", func() { 212 var expectedErr error 213 214 BeforeEach(func() { 215 expectedErr = actionerror.OrganizationNotFoundError{Name: "some-org"} 216 fakeCloudControllerClient.GetOrganizationsReturns(nil, ccv3.Warnings{"get-org-warning"}, expectedErr) 217 }) 218 219 It("returns the error", func() { 220 warnings, err := actor.EntitleIsolationSegmentToOrganizationByName("some-iso-seg", "some-org") 221 Expect(warnings).To(ConsistOf("get-org-warning", "get-iso-warning")) 222 Expect(err).To(MatchError(expectedErr)) 223 }) 224 }) 225 }) 226 227 When("retrieving the isolation segment errors", func() { 228 var expectedErr error 229 230 BeforeEach(func() { 231 expectedErr = actionerror.IsolationSegmentNotFoundError{Name: "some-iso-seg"} 232 fakeCloudControllerClient.GetIsolationSegmentsReturns(nil, ccv3.Warnings{"get-iso-warning"}, expectedErr) 233 }) 234 235 It("returns the error", func() { 236 warnings, err := actor.EntitleIsolationSegmentToOrganizationByName("some-iso-seg", "some-org") 237 Expect(warnings).To(ConsistOf("get-iso-warning")) 238 Expect(err).To(MatchError(expectedErr)) 239 }) 240 }) 241 }) 242 243 Describe("AssignIsolationSegmentToSpaceByNameAndSpace", func() { 244 When("the retrieving the isolation segment succeeds", func() { 245 BeforeEach(func() { 246 fakeCloudControllerClient.GetIsolationSegmentsReturns([]ccv3.IsolationSegment{ 247 { 248 GUID: "some-iso-guid", 249 Name: "some-iso-seg", 250 }, 251 }, ccv3.Warnings{"I r warnings", "I are two warnings"}, 252 nil, 253 ) 254 }) 255 256 When("the assignment is successful", func() { 257 BeforeEach(func() { 258 fakeCloudControllerClient.UpdateSpaceIsolationSegmentRelationshipReturns(resources.Relationship{GUID: "doesn't matter"}, ccv3.Warnings{"assignment-warnings-1", "assignment-warnings-2"}, nil) 259 }) 260 261 It("returns the warnings", func() { 262 warnings, err := actor.AssignIsolationSegmentToSpaceByNameAndSpace("some-iso-seg", "some-space-guid") 263 Expect(err).ToNot(HaveOccurred()) 264 Expect(warnings).To(ConsistOf("I r warnings", "I are two warnings", "assignment-warnings-1", "assignment-warnings-2")) 265 266 Expect(fakeCloudControllerClient.GetIsolationSegmentsCallCount()).To(Equal(1)) 267 Expect(fakeCloudControllerClient.GetIsolationSegmentsArgsForCall(0)).To(ConsistOf( 268 ccv3.Query{Key: ccv3.NameFilter, Values: []string{"some-iso-seg"}}, 269 )) 270 271 Expect(fakeCloudControllerClient.UpdateSpaceIsolationSegmentRelationshipCallCount()).To(Equal(1)) 272 spaceGUID, isoGUID := fakeCloudControllerClient.UpdateSpaceIsolationSegmentRelationshipArgsForCall(0) 273 Expect(spaceGUID).To(Equal("some-space-guid")) 274 Expect(isoGUID).To(Equal("some-iso-guid")) 275 }) 276 }) 277 278 When("the assignment errors", func() { 279 var expectedErr error 280 BeforeEach(func() { 281 expectedErr = errors.New("foo bar") 282 fakeCloudControllerClient.UpdateSpaceIsolationSegmentRelationshipReturns(resources.Relationship{}, ccv3.Warnings{"assignment-warnings-1", "assignment-warnings-2"}, expectedErr) 283 }) 284 285 It("returns the warnings and error", func() { 286 warnings, err := actor.AssignIsolationSegmentToSpaceByNameAndSpace("some-iso-seg", "some-space-guid") 287 Expect(err).To(MatchError(expectedErr)) 288 Expect(warnings).To(ConsistOf("I r warnings", "I are two warnings", "assignment-warnings-1", "assignment-warnings-2")) 289 }) 290 }) 291 }) 292 293 When("the retrieving the isolation segment errors", func() { 294 var expectedErr error 295 BeforeEach(func() { 296 expectedErr = errors.New("foo bar") 297 fakeCloudControllerClient.GetIsolationSegmentsReturns(nil, ccv3.Warnings{"I r warnings", "I are two warnings"}, expectedErr) 298 }) 299 300 It("returns the warnings and error", func() { 301 warnings, err := actor.AssignIsolationSegmentToSpaceByNameAndSpace("some-iso-seg", "some-space-guid") 302 Expect(err).To(MatchError(expectedErr)) 303 Expect(warnings).To(ConsistOf("I r warnings", "I are two warnings")) 304 }) 305 }) 306 }) 307 308 Describe("GetEffectiveIsolationSegmentBySpace", func() { 309 When("the retrieving the space isolation segment succeeds", func() { 310 BeforeEach(func() { 311 fakeCloudControllerClient.GetSpaceIsolationSegmentReturns(resources.Relationship{ 312 GUID: "some-iso-guid", 313 }, ccv3.Warnings{"I r warnings", "I are two warnings"}, 314 nil, 315 ) 316 }) 317 318 When("retrieving the isolation segment succeeds", func() { 319 BeforeEach(func() { 320 fakeCloudControllerClient.GetIsolationSegmentReturns(ccv3.IsolationSegment{ 321 Name: "some-iso", 322 }, 323 ccv3.Warnings{"iso-warnings-1", "iso-warnings-2"}, nil) 324 }) 325 326 It("returns the warnings and IsolationSegment", func() { 327 isolationSegment, warnings, err := actor.GetEffectiveIsolationSegmentBySpace("some-space-guid", "") 328 Expect(err).ToNot(HaveOccurred()) 329 Expect(warnings).To(ConsistOf("I r warnings", "I are two warnings", "iso-warnings-1", "iso-warnings-2")) 330 Expect(isolationSegment).To(Equal(IsolationSegment{Name: "some-iso"})) 331 332 Expect(fakeCloudControllerClient.GetSpaceIsolationSegmentCallCount()).To(Equal(1)) 333 Expect(fakeCloudControllerClient.GetSpaceIsolationSegmentArgsForCall(0)).To(Equal("some-space-guid")) 334 335 Expect(fakeCloudControllerClient.GetIsolationSegmentCallCount()).To(Equal(1)) 336 arg := fakeCloudControllerClient.GetIsolationSegmentArgsForCall(0) 337 Expect(arg).To(Equal("some-iso-guid")) 338 }) 339 }) 340 341 When("retrieving the isolation segment errors", func() { 342 var expectedErr error 343 BeforeEach(func() { 344 expectedErr = errors.New("foo bar") 345 fakeCloudControllerClient.GetIsolationSegmentReturns(ccv3.IsolationSegment{}, ccv3.Warnings{"iso-warnings-1", "iso-warnings-2"}, expectedErr) 346 }) 347 348 It("returns the warnings and error", func() { 349 _, warnings, err := actor.GetEffectiveIsolationSegmentBySpace("some-space-guid", "") 350 Expect(err).To(MatchError(expectedErr)) 351 Expect(warnings).To(ConsistOf("I r warnings", "I are two warnings", "iso-warnings-1", "iso-warnings-2")) 352 }) 353 }) 354 355 When("the space does not have an isolation segment", func() { 356 BeforeEach(func() { 357 fakeCloudControllerClient.GetSpaceIsolationSegmentReturns(resources.Relationship{ 358 GUID: "", 359 }, ccv3.Warnings{"warning-1", "warning-2"}, 360 nil, 361 ) 362 }) 363 364 When("no org isolation segment is passed in", func() { 365 It("returns NoRelationshipError", func() { 366 _, warnings, err := actor.GetEffectiveIsolationSegmentBySpace("some-space-guid", "") 367 Expect(err).To(MatchError(actionerror.NoRelationshipError{})) 368 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 369 }) 370 }) 371 372 When("an org default isolation segment is passed", func() { 373 When("retrieving the isolation segment is successful", func() { 374 BeforeEach(func() { 375 fakeCloudControllerClient.GetIsolationSegmentReturns( 376 ccv3.IsolationSegment{ 377 Name: "some-iso-segment", 378 GUID: "some-org-default-isolation-segment-guid", 379 }, 380 ccv3.Warnings{"warning-3", "warning-4"}, 381 nil) 382 }) 383 384 It("returns the org's default isolation segment", func() { 385 isolationSegment, warnings, err := actor.GetEffectiveIsolationSegmentBySpace("some-space-guid", "some-org-default-isolation-segment-guid") 386 Expect(isolationSegment).To(Equal(IsolationSegment{ 387 Name: "some-iso-segment", 388 GUID: "some-org-default-isolation-segment-guid", 389 })) 390 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "warning-3", "warning-4")) 391 Expect(err).ToNot(HaveOccurred()) 392 393 Expect(fakeCloudControllerClient.GetIsolationSegmentCallCount()).To(Equal(1)) 394 Expect(fakeCloudControllerClient.GetIsolationSegmentArgsForCall(0)).To(Equal("some-org-default-isolation-segment-guid")) 395 }) 396 }) 397 }) 398 }) 399 }) 400 401 When("the retrieving the space isolation segment errors", func() { 402 var expectedErr error 403 BeforeEach(func() { 404 expectedErr = errors.New("foo bar") 405 fakeCloudControllerClient.GetSpaceIsolationSegmentReturns(resources.Relationship{}, ccv3.Warnings{"I r warnings", "I are two warnings"}, expectedErr) 406 }) 407 408 It("returns the warnings and error", func() { 409 _, warnings, err := actor.GetEffectiveIsolationSegmentBySpace("some-space-guid", "") 410 Expect(err).To(MatchError(expectedErr)) 411 Expect(warnings).To(ConsistOf("I r warnings", "I are two warnings")) 412 }) 413 }) 414 }) 415 416 Describe("GetIsolationSegmentByName", func() { 417 When("the isolation segment exists", func() { 418 BeforeEach(func() { 419 fakeCloudControllerClient.GetIsolationSegmentsReturns([]ccv3.IsolationSegment{ 420 { 421 GUID: "some-iso-guid", 422 Name: "some-iso-seg", 423 }, 424 }, ccv3.Warnings{"I r warnings", "I are two warnings"}, 425 nil, 426 ) 427 }) 428 429 It("returns the isolation segment and warnings", func() { 430 segment, warnings, err := actor.GetIsolationSegmentByName("some-iso-seg") 431 Expect(err).NotTo(HaveOccurred()) 432 Expect(warnings).To(ConsistOf("I r warnings", "I are two warnings")) 433 Expect(segment).To(Equal(IsolationSegment{ 434 GUID: "some-iso-guid", 435 Name: "some-iso-seg", 436 })) 437 438 Expect(fakeCloudControllerClient.GetIsolationSegmentsCallCount()).To(Equal(1)) 439 Expect(fakeCloudControllerClient.GetIsolationSegmentsArgsForCall(0)).To(ConsistOf( 440 ccv3.Query{Key: ccv3.NameFilter, Values: []string{"some-iso-seg"}}, 441 )) 442 }) 443 }) 444 445 When("the isolation segment does *not* exist", func() { 446 BeforeEach(func() { 447 fakeCloudControllerClient.GetIsolationSegmentsReturns(nil, ccv3.Warnings{"I r warnings", "I are two warnings"}, nil) 448 }) 449 450 It("returns an IsolationSegmentNotFoundError", func() { 451 _, warnings, err := actor.GetIsolationSegmentByName("some-iso-seg") 452 Expect(err).To(MatchError(actionerror.IsolationSegmentNotFoundError{Name: "some-iso-seg"})) 453 Expect(warnings).To(ConsistOf("I r warnings", "I are two warnings")) 454 }) 455 }) 456 457 When("the cloud controller errors", func() { 458 var expectedErr error 459 BeforeEach(func() { 460 expectedErr = errors.New("some-cc-error") 461 fakeCloudControllerClient.GetIsolationSegmentsReturns(nil, ccv3.Warnings{"I r warnings", "I are two warnings"}, expectedErr) 462 }) 463 464 It("returns the error and all warnings", func() { 465 _, warnings, err := actor.GetIsolationSegmentByName("some-iso-seg") 466 Expect(err).To(MatchError(expectedErr)) 467 Expect(warnings).To(ConsistOf("I r warnings", "I are two warnings")) 468 }) 469 }) 470 }) 471 472 Describe("GetIsolationSegmentsByOrganization", func() { 473 When("there are isolation segments entitled to this org", func() { 474 BeforeEach(func() { 475 fakeCloudControllerClient.GetIsolationSegmentsReturns( 476 []ccv3.IsolationSegment{ 477 {Name: "some-iso-seg-1"}, 478 {Name: "some-iso-seg-2"}, 479 }, 480 ccv3.Warnings{"get isolation segments warning"}, 481 nil, 482 ) 483 }) 484 485 It("returns the isolation segments and warnings", func() { 486 isolationSegments, warnings, err := actor.GetIsolationSegmentsByOrganization("some-org-guid") 487 Expect(err).ToNot(HaveOccurred()) 488 489 Expect(isolationSegments).To(ConsistOf( 490 IsolationSegment{Name: "some-iso-seg-1"}, 491 IsolationSegment{Name: "some-iso-seg-2"}, 492 )) 493 Expect(warnings).To(ConsistOf("get isolation segments warning")) 494 495 Expect(fakeCloudControllerClient.GetIsolationSegmentsCallCount()).To(Equal(1)) 496 Expect(fakeCloudControllerClient.GetIsolationSegmentsArgsForCall(0)).To(ConsistOf( 497 ccv3.Query{Key: ccv3.OrganizationGUIDFilter, Values: []string{"some-org-guid"}}, 498 )) 499 }) 500 }) 501 502 When("the cloud controller client returns an error", func() { 503 var expectedError error 504 505 BeforeEach(func() { 506 expectedError = errors.New("some cc error") 507 fakeCloudControllerClient.GetIsolationSegmentsReturns( 508 []ccv3.IsolationSegment{}, 509 ccv3.Warnings{"get isolation segments warning"}, 510 expectedError) 511 }) 512 513 It("returns the error and warnings", func() { 514 _, warnings, err := actor.GetIsolationSegmentsByOrganization("some-org-guid") 515 Expect(warnings).To(ConsistOf("get isolation segments warning")) 516 Expect(err).To(MatchError(expectedError)) 517 }) 518 }) 519 }) 520 521 Describe("GetIsolationSegmentSummaries", func() { 522 When("getting isolation segments succeeds", func() { 523 BeforeEach(func() { 524 fakeCloudControllerClient.GetIsolationSegmentsReturns([]ccv3.IsolationSegment{ 525 { 526 Name: "iso-seg-1", 527 GUID: "iso-guid-1", 528 }, 529 { 530 Name: "iso-seg-2", 531 GUID: "iso-guid-2", 532 }, 533 }, ccv3.Warnings{"get-iso-warning"}, nil) 534 }) 535 536 When("getting entitled organizations succeeds", func() { 537 BeforeEach(func() { 538 fakeCloudControllerClient.GetIsolationSegmentOrganizationsReturnsOnCall(0, []resources.Organization{}, ccv3.Warnings{"get-entitled-orgs-warning-1"}, nil) 539 fakeCloudControllerClient.GetIsolationSegmentOrganizationsReturnsOnCall(1, []resources.Organization{ 540 { 541 Name: "iso-2-org-1", 542 GUID: "iso-2-org-guid-1", 543 }, 544 { 545 Name: "iso-2-org-2", 546 GUID: "iso-2-org-guid-2", 547 }, 548 }, ccv3.Warnings{"get-entitled-orgs-warning-2"}, nil) 549 }) 550 551 It("returns all isolation segment summaries and all warnings", func() { 552 isoSummaries, warnings, err := actor.GetIsolationSegmentSummaries() 553 Expect(warnings).To(ConsistOf("get-iso-warning", "get-entitled-orgs-warning-1", "get-entitled-orgs-warning-2")) 554 Expect(err).ToNot(HaveOccurred()) 555 Expect(isoSummaries).To(ConsistOf([]IsolationSegmentSummary{ 556 { 557 Name: "iso-seg-1", 558 EntitledOrgs: []string{}, 559 }, 560 { 561 Name: "iso-seg-2", 562 EntitledOrgs: []string{"iso-2-org-1", "iso-2-org-2"}, 563 }, 564 })) 565 566 Expect(fakeCloudControllerClient.GetIsolationSegmentsCallCount()).To(Equal(1)) 567 Expect(fakeCloudControllerClient.GetIsolationSegmentsArgsForCall(0)).To(BeEmpty()) 568 Expect(fakeCloudControllerClient.GetIsolationSegmentOrganizationsCallCount()).To(Equal(2)) 569 Expect(fakeCloudControllerClient.GetIsolationSegmentOrganizationsArgsForCall(0)).To(Equal("iso-guid-1")) 570 Expect(fakeCloudControllerClient.GetIsolationSegmentOrganizationsArgsForCall(1)).To(Equal("iso-guid-2")) 571 }) 572 }) 573 574 When("getting entitled organizations fails", func() { 575 var expectedErr error 576 577 BeforeEach(func() { 578 expectedErr = errors.New("some-error") 579 fakeCloudControllerClient.GetIsolationSegmentOrganizationsReturns(nil, ccv3.Warnings{"get-entitled-orgs-warning"}, expectedErr) 580 }) 581 582 It("returns the error and warnings", func() { 583 _, warnings, err := actor.GetIsolationSegmentSummaries() 584 Expect(warnings).To(ConsistOf("get-iso-warning", "get-entitled-orgs-warning")) 585 Expect(err).To(MatchError(expectedErr)) 586 }) 587 }) 588 }) 589 590 When("getting isolation segments fails", func() { 591 var expectedErr error 592 593 BeforeEach(func() { 594 expectedErr = errors.New("some-error") 595 fakeCloudControllerClient.GetIsolationSegmentsReturns(nil, ccv3.Warnings{"get-iso-warning"}, expectedErr) 596 }) 597 598 It("returns the error and warnings", func() { 599 _, warnings, err := actor.GetIsolationSegmentSummaries() 600 Expect(warnings).To(ConsistOf("get-iso-warning")) 601 Expect(err).To(MatchError(expectedErr)) 602 }) 603 }) 604 }) 605 606 Describe("DeleteIsolationSegmentOrganizationByName", func() { 607 When("the isolation segment exists", func() { 608 BeforeEach(func() { 609 fakeCloudControllerClient.GetIsolationSegmentsReturns([]ccv3.IsolationSegment{ 610 { 611 Name: "iso-1", 612 GUID: "iso-1-guid-1", 613 }, 614 }, ccv3.Warnings{"get-entitled-orgs-warning-1"}, nil) 615 }) 616 617 When("the organization exists", func() { 618 BeforeEach(func() { 619 fakeCloudControllerClient.GetOrganizationsReturns([]resources.Organization{ 620 { 621 Name: "org-1", 622 GUID: "org-guid-1", 623 }, 624 }, ccv3.Warnings{"get-orgs-warning-1"}, nil) 625 }) 626 627 When("the revocation is successful", func() { 628 BeforeEach(func() { 629 fakeCloudControllerClient.DeleteIsolationSegmentOrganizationReturns(ccv3.Warnings{"revoke-warnings-1"}, nil) 630 }) 631 632 It("returns the warnings", func() { 633 warnings, err := actor.DeleteIsolationSegmentOrganizationByName("iso-1", "org-1") 634 Expect(err).ToNot(HaveOccurred()) 635 Expect(warnings).To(ConsistOf("get-entitled-orgs-warning-1", "get-orgs-warning-1", "revoke-warnings-1")) 636 637 Expect(fakeCloudControllerClient.DeleteIsolationSegmentOrganizationCallCount()).To(Equal(1)) 638 isoGUID, orgGUID := fakeCloudControllerClient.DeleteIsolationSegmentOrganizationArgsForCall(0) 639 Expect(isoGUID).To(Equal("iso-1-guid-1")) 640 Expect(orgGUID).To(Equal("org-guid-1")) 641 }) 642 }) 643 644 When("the revocation errors", func() { 645 var expectedErr error 646 647 BeforeEach(func() { 648 expectedErr = errors.New("Banana!") 649 fakeCloudControllerClient.DeleteIsolationSegmentOrganizationReturns(ccv3.Warnings{"revoke-warnings-1"}, expectedErr) 650 }) 651 652 It("from Organization", func() { 653 warnings, err := actor.DeleteIsolationSegmentOrganizationByName("iso-1", "org-1") 654 Expect(err).To(MatchError(expectedErr)) 655 Expect(warnings).To(ConsistOf("get-entitled-orgs-warning-1", "get-orgs-warning-1", "revoke-warnings-1")) 656 }) 657 }) 658 }) 659 660 When("getting the organization errors", func() { 661 BeforeEach(func() { 662 fakeCloudControllerClient.GetOrganizationsReturns(nil, ccv3.Warnings{"get-orgs-warning-1"}, nil) 663 }) 664 665 It("returns back the error", func() { 666 warnings, err := actor.DeleteIsolationSegmentOrganizationByName("iso-1", "org-1") 667 Expect(err).To(MatchError(actionerror.OrganizationNotFoundError{Name: "org-1"})) 668 Expect(warnings).To(ConsistOf("get-entitled-orgs-warning-1", "get-orgs-warning-1")) 669 670 Expect(fakeCloudControllerClient.DeleteIsolationSegmentOrganizationCallCount()).To(Equal(0)) 671 }) 672 }) 673 }) 674 675 When("getting the isolation segment errors", func() { 676 BeforeEach(func() { 677 fakeCloudControllerClient.GetIsolationSegmentsReturns(nil, ccv3.Warnings{"get-entitled-orgs-warning-1"}, nil) 678 }) 679 680 It("returns back the error", func() { 681 warnings, err := actor.DeleteIsolationSegmentOrganizationByName("iso-2-org-1", "org-1") 682 Expect(err).To(MatchError(actionerror.IsolationSegmentNotFoundError{Name: "iso-2-org-1"})) 683 Expect(warnings).To(ConsistOf("get-entitled-orgs-warning-1")) 684 685 Expect(fakeCloudControllerClient.GetOrganizationsCallCount()).To(Equal(0)) 686 }) 687 }) 688 689 }) 690 691 Describe("GetOrganizationDefaultIsolationSegment", func() { 692 When("fetching the resource is successful", func() { 693 BeforeEach(func() { 694 fakeCloudControllerClient.GetOrganizationDefaultIsolationSegmentReturns( 695 resources.Relationship{GUID: "iso-seg-guid"}, 696 ccv3.Warnings{"warning-1", "warning-2"}, 697 nil, 698 ) 699 }) 700 701 It("returns all warnings", func() { 702 defaultIsoSegGUID, warnings, err := actor.GetOrganizationDefaultIsolationSegment("some-org-guid") 703 Expect(err).ToNot(HaveOccurred()) 704 705 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 706 707 Expect(fakeCloudControllerClient.GetOrganizationDefaultIsolationSegmentCallCount()).To(Equal(1)) 708 orgGUID := fakeCloudControllerClient.GetOrganizationDefaultIsolationSegmentArgsForCall(0) 709 Expect(orgGUID).To(Equal("some-org-guid")) 710 Expect(defaultIsoSegGUID).To(Equal("iso-seg-guid")) 711 }) 712 }) 713 714 When("fetching the resourece fails", func() { 715 BeforeEach(func() { 716 fakeCloudControllerClient.GetOrganizationDefaultIsolationSegmentReturns( 717 resources.Relationship{}, 718 ccv3.Warnings{"warning-1", "warning-2"}, 719 errors.New("some-error"), 720 ) 721 }) 722 723 It("returns the error and all warnings", func() { 724 _, warnings, err := actor.GetOrganizationDefaultIsolationSegment("some-org-guid") 725 Expect(err).To(MatchError("some-error")) 726 727 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 728 }) 729 }) 730 }) 731 732 Describe("SetOrganizationDefaultIsolationSegment", func() { 733 When("the assignment is successful", func() { 734 BeforeEach(func() { 735 fakeCloudControllerClient.UpdateOrganizationDefaultIsolationSegmentRelationshipReturns( 736 resources.Relationship{GUID: "some-guid"}, 737 ccv3.Warnings{"warning-1", "warning-2"}, 738 nil, 739 ) 740 }) 741 742 It("returns all warnings", func() { 743 warnings, err := actor.SetOrganizationDefaultIsolationSegment("some-org-guid", "some-iso-seg-guid") 744 Expect(err).ToNot(HaveOccurred()) 745 746 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 747 748 Expect(fakeCloudControllerClient.UpdateOrganizationDefaultIsolationSegmentRelationshipCallCount()).To(Equal(1)) 749 orgGUID, isoSegGUID := fakeCloudControllerClient.UpdateOrganizationDefaultIsolationSegmentRelationshipArgsForCall(0) 750 Expect(orgGUID).To(Equal("some-org-guid")) 751 Expect(isoSegGUID).To(Equal("some-iso-seg-guid")) 752 }) 753 }) 754 755 When("the assignment fails", func() { 756 BeforeEach(func() { 757 fakeCloudControllerClient.UpdateOrganizationDefaultIsolationSegmentRelationshipReturns( 758 resources.Relationship{GUID: "some-guid"}, 759 ccv3.Warnings{"warning-1", "warning-2"}, 760 errors.New("some-error"), 761 ) 762 }) 763 764 It("returns the error and all warnings", func() { 765 warnings, err := actor.SetOrganizationDefaultIsolationSegment("some-org-guid", "some-iso-seg-guid") 766 Expect(err).To(MatchError("some-error")) 767 768 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 769 }) 770 }) 771 }) 772 773 Describe("ResetOrganizationDefaultIsolationSegment", func() { 774 When("the assignment is successful", func() { 775 BeforeEach(func() { 776 fakeCloudControllerClient.UpdateOrganizationDefaultIsolationSegmentRelationshipReturns( 777 resources.Relationship{GUID: "some-guid"}, 778 ccv3.Warnings{"warning-1", "warning-2"}, 779 nil, 780 ) 781 }) 782 783 It("returns all warnings", func() { 784 warnings, err := actor.ResetOrganizationDefaultIsolationSegment("some-org-guid") 785 Expect(err).ToNot(HaveOccurred()) 786 787 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 788 789 Expect(fakeCloudControllerClient.UpdateOrganizationDefaultIsolationSegmentRelationshipCallCount()).To(Equal(1)) 790 orgGUID, isoSegGUID := fakeCloudControllerClient.UpdateOrganizationDefaultIsolationSegmentRelationshipArgsForCall(0) 791 Expect(orgGUID).To(Equal("some-org-guid")) 792 Expect(isoSegGUID).To(BeEmpty()) 793 }) 794 }) 795 796 When("the assignment fails", func() { 797 BeforeEach(func() { 798 fakeCloudControllerClient.UpdateOrganizationDefaultIsolationSegmentRelationshipReturns( 799 resources.Relationship{GUID: "some-guid"}, 800 ccv3.Warnings{"warning-1", "warning-2"}, 801 errors.New("some-error"), 802 ) 803 }) 804 805 It("returns the error and all warnings", func() { 806 warnings, err := actor.ResetOrganizationDefaultIsolationSegment("some-org-guid") 807 Expect(err).To(MatchError("some-error")) 808 809 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 810 }) 811 }) 812 }) 813 })