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