github.com/ablease/cli@v6.37.1-0.20180613014814-3adbb7d7fb19+incompatible/actor/v2action/service_plan_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("Service Plan 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("GetServicePlan", func() { 25 var ( 26 servicePlan ServicePlan 27 servicePlanWarnings Warnings 28 servicePlanErr error 29 ) 30 31 JustBeforeEach(func() { 32 servicePlan, servicePlanWarnings, servicePlanErr = actor.GetServicePlan("some-service-plan-guid") 33 }) 34 35 Context("when the service plan exists", func() { 36 var returnedServicePlan ccv2.ServicePlan 37 38 BeforeEach(func() { 39 returnedServicePlan = ccv2.ServicePlan{ 40 GUID: "some-service-plan-guid", 41 Name: "some-service-plan", 42 } 43 fakeCloudControllerClient.GetServicePlanReturns( 44 returnedServicePlan, 45 ccv2.Warnings{"get-service-plan-warning"}, 46 nil) 47 }) 48 49 It("returns the service plan and all warnings", func() { 50 Expect(servicePlanErr).ToNot(HaveOccurred()) 51 Expect(servicePlan).To(Equal(ServicePlan(returnedServicePlan))) 52 Expect(servicePlanWarnings).To(ConsistOf("get-service-plan-warning")) 53 54 Expect(fakeCloudControllerClient.GetServicePlanCallCount()).To(Equal(1)) 55 Expect(fakeCloudControllerClient.GetServicePlanArgsForCall(0)).To(Equal("some-service-plan-guid")) 56 }) 57 }) 58 59 Context("when an error is encountered getting the service plan", func() { 60 var expectedErr error 61 62 BeforeEach(func() { 63 expectedErr = errors.New("some-error") 64 fakeCloudControllerClient.GetServicePlanReturns( 65 ccv2.ServicePlan{}, 66 ccv2.Warnings{"get-service-plan-warning"}, 67 expectedErr) 68 }) 69 70 It("returns the errors and all warnings", func() { 71 Expect(servicePlanErr).To(MatchError(expectedErr)) 72 Expect(servicePlan).To(Equal(ServicePlan{})) 73 Expect(servicePlanWarnings).To(ConsistOf("get-service-plan-warning")) 74 75 Expect(fakeCloudControllerClient.GetServicePlanCallCount()).To(Equal(1)) 76 Expect(fakeCloudControllerClient.GetServicePlanArgsForCall(0)).To(Equal("some-service-plan-guid")) 77 }) 78 }) 79 }) 80 })