github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/actor/v2action/service_instance_shared_to_test.go (about) 1 package v2action_test 2 3 import ( 4 "errors" 5 6 . "code.cloudfoundry.org/cli/actor/v2action" 7 "code.cloudfoundry.org/cli/actor/v2action/v2actionfakes" 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 ) 12 13 var _ = Describe("ServiceInstanceSharedTo Actions", func() { 14 var ( 15 actor *Actor 16 fakeCloudControllerClient *v2actionfakes.FakeCloudControllerClient 17 ) 18 19 BeforeEach(func() { 20 fakeCloudControllerClient = new(v2actionfakes.FakeCloudControllerClient) 21 actor = NewActor(fakeCloudControllerClient, nil, nil) 22 }) 23 24 Describe("GetServiceInstanceSharedTosByServiceInstance", func() { 25 var ( 26 serviceInstanceGUID string 27 28 sharedTos []ServiceInstanceSharedTo 29 warnings Warnings 30 getErr error 31 ) 32 33 BeforeEach(func() { 34 serviceInstanceGUID = "some-service-instance-guid" 35 }) 36 37 JustBeforeEach(func() { 38 sharedTos, warnings, getErr = actor.GetServiceInstanceSharedTosByServiceInstance(serviceInstanceGUID) 39 }) 40 41 When("no errors are encountered getting the service instance shared_to list", func() { 42 var returnedSharedTos []ccv2.ServiceInstanceSharedTo 43 BeforeEach(func() { 44 returnedSharedTos = []ccv2.ServiceInstanceSharedTo{ 45 { 46 SpaceGUID: "some-space-guid", 47 SpaceName: "some-space-name", 48 OrganizationName: "some-org-name", 49 BoundAppCount: 3, 50 }, 51 { 52 SpaceGUID: "another-space-guid", 53 SpaceName: "another-space-name", 54 OrganizationName: "another-org-name", 55 BoundAppCount: 2, 56 }, 57 } 58 fakeCloudControllerClient.GetServiceInstanceSharedTosReturns( 59 returnedSharedTos, 60 ccv2.Warnings{"get-service-instance-shared-to-warning"}, 61 nil, 62 ) 63 }) 64 65 It("returns the service instance shared_to list and all warnings", func() { 66 Expect(getErr).ToNot(HaveOccurred()) 67 Expect(sharedTos).To(ConsistOf(ServiceInstanceSharedTo(returnedSharedTos[0]), ServiceInstanceSharedTo(returnedSharedTos[1]))) 68 Expect(warnings).To(ConsistOf("get-service-instance-shared-to-warning")) 69 70 Expect(fakeCloudControllerClient.GetServiceInstanceSharedTosCallCount()).To(Equal(1)) 71 Expect(fakeCloudControllerClient.GetServiceInstanceSharedTosArgsForCall(0)).To(Equal("some-service-instance-guid")) 72 }) 73 }) 74 75 When("an error is encountered getting the service instance shared_to list", func() { 76 var expectedErr error 77 BeforeEach(func() { 78 expectedErr = errors.New("some-error") 79 fakeCloudControllerClient.GetServiceInstanceSharedTosReturns( 80 nil, 81 ccv2.Warnings{"get-service-instance-shared-to-warning"}, 82 expectedErr, 83 ) 84 }) 85 86 It("returns the error and all warnings", func() { 87 Expect(getErr).To(MatchError(expectedErr)) 88 Expect(warnings).To(ConsistOf("get-service-instance-shared-to-warning")) 89 90 Expect(fakeCloudControllerClient.GetServiceInstanceSharedTosCallCount()).To(Equal(1)) 91 Expect(fakeCloudControllerClient.GetServiceInstanceSharedTosArgsForCall(0)).To(Equal("some-service-instance-guid")) 92 }) 93 }) 94 }) 95 })