github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/actor/v3action/space_test.go (about)

     1  package v3action_test
     2  
     3  import (
     4  	"errors"
     5  
     6  	. "code.cloudfoundry.org/cli/actor/v3action"
     7  	"code.cloudfoundry.org/cli/actor/v3action/v3actionfakes"
     8  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  )
    12  
    13  var _ = Describe("Space", func() {
    14  	var (
    15  		actor                     *Actor
    16  		fakeCloudControllerClient *v3actionfakes.FakeCloudControllerClient
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		fakeCloudControllerClient = new(v3actionfakes.FakeCloudControllerClient)
    21  		fakeConfig := new(v3actionfakes.FakeConfig)
    22  		actor = NewActor(nil, fakeCloudControllerClient, fakeConfig)
    23  	})
    24  
    25  	Describe("ResetSpaceIsolationSegment", func() {
    26  		Context("when the organization does not have a default isolation segment", func() {
    27  			BeforeEach(func() {
    28  				fakeCloudControllerClient.AssignSpaceToIsolationSegmentReturns(
    29  					ccv3.Relationship{GUID: ""},
    30  					ccv3.Warnings{"warning-1", "warning-2"}, nil)
    31  			})
    32  
    33  			It("returns an empty isolation segment GUID", func() {
    34  				newIsolationSegmentName, warnings, err := actor.ResetSpaceIsolationSegment("some-org-guid", "some-space-guid")
    35  
    36  				Expect(err).ToNot(HaveOccurred())
    37  				Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
    38  				Expect(newIsolationSegmentName).To(BeEmpty())
    39  
    40  				Expect(fakeCloudControllerClient.AssignSpaceToIsolationSegmentCallCount()).To(Equal(1))
    41  				spaceGUID, isolationSegmentGUID := fakeCloudControllerClient.AssignSpaceToIsolationSegmentArgsForCall(0)
    42  				Expect(spaceGUID).To(Equal("some-space-guid"))
    43  				Expect(isolationSegmentGUID).To(BeEmpty())
    44  
    45  				Expect(fakeCloudControllerClient.GetOrganizationDefaultIsolationSegmentCallCount()).To(Equal(1))
    46  				orgGUID := fakeCloudControllerClient.GetOrganizationDefaultIsolationSegmentArgsForCall(0)
    47  				Expect(orgGUID).To(Equal("some-org-guid"))
    48  
    49  				Expect(fakeCloudControllerClient.GetIsolationSegmentCallCount()).To(Equal(0))
    50  			})
    51  		})
    52  
    53  		Context("when the organization has a default isolation segment", func() {
    54  			BeforeEach(func() {
    55  				fakeCloudControllerClient.AssignSpaceToIsolationSegmentReturns(
    56  					ccv3.Relationship{GUID: ""},
    57  					ccv3.Warnings{"warning-1", "warning-2"}, nil)
    58  				fakeCloudControllerClient.GetOrganizationDefaultIsolationSegmentReturns(
    59  					ccv3.Relationship{GUID: "some-iso-guid"},
    60  					ccv3.Warnings{"warning-3", "warning-4"}, nil)
    61  				fakeCloudControllerClient.GetIsolationSegmentReturns(
    62  					ccv3.IsolationSegment{Name: "some-iso-name"},
    63  					ccv3.Warnings{"warning-5", "warning-6"}, nil)
    64  			})
    65  
    66  			It("returns the org's isolation segment GUID", func() {
    67  				newIsolationSegmentName, warnings, err := actor.ResetSpaceIsolationSegment("some-org-guid", "some-space-guid")
    68  
    69  				Expect(fakeCloudControllerClient.AssignSpaceToIsolationSegmentCallCount()).To(Equal(1))
    70  				spaceGUID, isolationSegmentGUID := fakeCloudControllerClient.AssignSpaceToIsolationSegmentArgsForCall(0)
    71  				Expect(spaceGUID).To(Equal("some-space-guid"))
    72  				Expect(isolationSegmentGUID).To(BeEmpty())
    73  
    74  				Expect(fakeCloudControllerClient.GetOrganizationDefaultIsolationSegmentCallCount()).To(Equal(1))
    75  				orgGUID := fakeCloudControllerClient.GetOrganizationDefaultIsolationSegmentArgsForCall(0)
    76  				Expect(orgGUID).To(Equal("some-org-guid"))
    77  
    78  				Expect(fakeCloudControllerClient.GetIsolationSegmentCallCount()).To(Equal(1))
    79  				isoSegGUID := fakeCloudControllerClient.GetIsolationSegmentArgsForCall(0)
    80  				Expect(isoSegGUID).To(Equal("some-iso-guid"))
    81  
    82  				Expect(err).ToNot(HaveOccurred())
    83  				Expect(warnings).To(ConsistOf("warning-1", "warning-2", "warning-3", "warning-4", "warning-5", "warning-6"))
    84  				Expect(newIsolationSegmentName).To(Equal("some-iso-name"))
    85  			})
    86  		})
    87  
    88  		Context("when assigning the space returns an error", func() {
    89  			var expectedErr error
    90  
    91  			BeforeEach(func() {
    92  				expectedErr = errors.New("some error")
    93  				fakeCloudControllerClient.AssignSpaceToIsolationSegmentReturns(
    94  					ccv3.Relationship{GUID: ""},
    95  					ccv3.Warnings{"warning-1", "warning-2"}, expectedErr)
    96  			})
    97  
    98  			It("returns warnings and the error", func() {
    99  				_, warnings, err := actor.ResetSpaceIsolationSegment("some-org-guid", "some-space-guid")
   100  				Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
   101  				Expect(err).To(MatchError(expectedErr))
   102  			})
   103  		})
   104  
   105  		Context("when getting the org's default isolation segments returns an error", func() {
   106  			var expectedErr error
   107  
   108  			BeforeEach(func() {
   109  				expectedErr = errors.New("some error")
   110  				fakeCloudControllerClient.AssignSpaceToIsolationSegmentReturns(
   111  					ccv3.Relationship{GUID: ""},
   112  					ccv3.Warnings{"warning-1", "warning-2"}, nil)
   113  				fakeCloudControllerClient.GetOrganizationDefaultIsolationSegmentReturns(
   114  					ccv3.Relationship{GUID: "some-iso-guid"},
   115  					ccv3.Warnings{"warning-3", "warning-4"}, expectedErr)
   116  			})
   117  
   118  			It("returns the warnings and an error", func() {
   119  				_, warnings, err := actor.ResetSpaceIsolationSegment("some-org-guid", "some-space-guid")
   120  				Expect(warnings).To(ConsistOf("warning-1", "warning-2", "warning-3", "warning-4"))
   121  				Expect(err).To(MatchError(expectedErr))
   122  			})
   123  		})
   124  
   125  		Context("when getting the isolation segment returns an error", func() {
   126  			var expectedErr error
   127  
   128  			BeforeEach(func() {
   129  				expectedErr = errors.New("some error")
   130  				fakeCloudControllerClient.AssignSpaceToIsolationSegmentReturns(
   131  					ccv3.Relationship{GUID: ""},
   132  					ccv3.Warnings{"warning-1", "warning-2"}, nil)
   133  				fakeCloudControllerClient.GetOrganizationDefaultIsolationSegmentReturns(
   134  					ccv3.Relationship{GUID: "some-iso-guid"},
   135  					ccv3.Warnings{"warning-3", "warning-4"}, nil)
   136  				fakeCloudControllerClient.GetIsolationSegmentReturns(
   137  					ccv3.IsolationSegment{Name: "some-iso-name"},
   138  					ccv3.Warnings{"warning-5", "warning-6"}, expectedErr)
   139  			})
   140  
   141  			It("returns the warnings and an error", func() {
   142  				_, warnings, err := actor.ResetSpaceIsolationSegment("some-org-guid", "some-space-guid")
   143  				Expect(warnings).To(ConsistOf("warning-1", "warning-2", "warning-3", "warning-4", "warning-5", "warning-6"))
   144  				Expect(err).To(MatchError(expectedErr))
   145  			})
   146  		})
   147  	})
   148  })