github.com/swisscom/cloudfoundry-cli@v7.1.0+incompatible/actor/v2action/service_instance_shared_from_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("ServiceInstanceSharedFrom 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("GetServiceInstanceSharedFromByServiceInstance", func() { 25 var ( 26 serviceInstanceGUID string 27 28 sharedFrom ServiceInstanceSharedFrom 29 warnings Warnings 30 getErr error 31 ) 32 33 BeforeEach(func() { 34 serviceInstanceGUID = "some-service-instance-guid" 35 }) 36 37 JustBeforeEach(func() { 38 sharedFrom, warnings, getErr = actor.GetServiceInstanceSharedFromByServiceInstance(serviceInstanceGUID) 39 }) 40 41 When("no errors are encountered getting the service instance shared_from object", func() { 42 var returnedSharedFrom ccv2.ServiceInstanceSharedFrom 43 BeforeEach(func() { 44 returnedSharedFrom = ccv2.ServiceInstanceSharedFrom{ 45 SpaceGUID: "some-space-guid", 46 SpaceName: "some-space-name", 47 OrganizationName: "some-org-name", 48 } 49 fakeCloudControllerClient.GetServiceInstanceSharedFromReturns( 50 returnedSharedFrom, 51 ccv2.Warnings{"get-service-instance-shared-from-warning"}, 52 nil, 53 ) 54 }) 55 56 It("returns the service instance shared_from object and all warnings", func() { 57 Expect(getErr).ToNot(HaveOccurred()) 58 Expect(sharedFrom).To(Equal(ServiceInstanceSharedFrom(returnedSharedFrom))) 59 Expect(warnings).To(ConsistOf("get-service-instance-shared-from-warning")) 60 61 Expect(fakeCloudControllerClient.GetServiceInstanceSharedFromCallCount()).To(Equal(1)) 62 Expect(fakeCloudControllerClient.GetServiceInstanceSharedFromArgsForCall(0)).To(Equal("some-service-instance-guid")) 63 }) 64 }) 65 66 When("an error is encountered getting the service instance shared_from object", func() { 67 var expectedErr error 68 BeforeEach(func() { 69 expectedErr = errors.New("some-error") 70 fakeCloudControllerClient.GetServiceInstanceSharedFromReturns( 71 ccv2.ServiceInstanceSharedFrom{}, 72 ccv2.Warnings{"get-service-instance-shared-from-warning"}, 73 expectedErr, 74 ) 75 }) 76 77 It("returns the error and all warnings", func() { 78 Expect(getErr).To(MatchError(expectedErr)) 79 Expect(warnings).To(ConsistOf("get-service-instance-shared-from-warning")) 80 81 Expect(fakeCloudControllerClient.GetServiceInstanceSharedFromCallCount()).To(Equal(1)) 82 Expect(fakeCloudControllerClient.GetServiceInstanceSharedFromArgsForCall(0)).To(Equal("some-service-instance-guid")) 83 }) 84 }) 85 }) 86 })