github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/actor/v7action/relationship_list_test.go (about)

     1  package v7action_test
     2  
     3  import (
     4  	"errors"
     5  
     6  	. "code.cloudfoundry.org/cli/actor/v7action"
     7  	"code.cloudfoundry.org/cli/actor/v7action/v7actionfakes"
     8  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
     9  	"code.cloudfoundry.org/cli/resources"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  )
    13  
    14  var _ = Describe("Relationship List Actions", func() {
    15  	var (
    16  		actor                     *Actor
    17  		fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient
    18  	)
    19  
    20  	BeforeEach(func() {
    21  		fakeCloudControllerClient = new(v7actionfakes.FakeCloudControllerClient)
    22  		actor = NewActor(fakeCloudControllerClient, nil, nil, nil, nil, nil)
    23  	})
    24  
    25  	Describe("ShareServiceInstanceToSpaces", func() {
    26  		var (
    27  			serviceInstanceGUID string
    28  			shareToSpaceGUID    string
    29  
    30  			relationshipList resources.RelationshipList
    31  			warnings         Warnings
    32  			shareErr         error
    33  		)
    34  
    35  		BeforeEach(func() {
    36  			serviceInstanceGUID = "some-service-instance-guid"
    37  			shareToSpaceGUID = "some-space-guid"
    38  		})
    39  
    40  		JustBeforeEach(func() {
    41  			relationshipList, warnings, shareErr = actor.ShareServiceInstanceToSpaces(
    42  				serviceInstanceGUID,
    43  				[]string{shareToSpaceGUID})
    44  		})
    45  
    46  		When("no errors occur sharing the service instance", func() {
    47  			var returnedRelationshipList resources.RelationshipList
    48  
    49  			BeforeEach(func() {
    50  				returnedRelationshipList = resources.RelationshipList{
    51  					GUIDs: []string{"some-space-guid"},
    52  				}
    53  				fakeCloudControllerClient.ShareServiceInstanceToSpacesReturns(
    54  					returnedRelationshipList,
    55  					ccv3.Warnings{"share-service-instance-warning"},
    56  					nil)
    57  			})
    58  
    59  			It("does not return an error and returns warnings", func() {
    60  				Expect(shareErr).ToNot(HaveOccurred())
    61  				Expect(relationshipList).To(Equal(returnedRelationshipList))
    62  				Expect(warnings).To(ConsistOf("share-service-instance-warning"))
    63  
    64  				Expect(fakeCloudControllerClient.ShareServiceInstanceToSpacesCallCount()).To(Equal(1))
    65  				serviceInstanceGUIDArg, spaceGUIDsArg := fakeCloudControllerClient.ShareServiceInstanceToSpacesArgsForCall(0)
    66  				Expect(serviceInstanceGUIDArg).To(Equal(serviceInstanceGUID))
    67  				Expect(spaceGUIDsArg).To(Equal([]string{shareToSpaceGUID}))
    68  			})
    69  		})
    70  
    71  		When("an error occurs sharing the service instance", func() {
    72  			var expectedErr error
    73  
    74  			BeforeEach(func() {
    75  				expectedErr = errors.New("share service instance error")
    76  				fakeCloudControllerClient.ShareServiceInstanceToSpacesReturns(
    77  					resources.RelationshipList{},
    78  					ccv3.Warnings{"share-service-instance-warning"},
    79  					expectedErr)
    80  			})
    81  
    82  			It("returns the error and warnings", func() {
    83  				Expect(shareErr).To(MatchError(expectedErr))
    84  				Expect(warnings).To(ConsistOf("share-service-instance-warning"))
    85  			})
    86  		})
    87  	})
    88  })