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