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