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