github.com/swisscom/cloudfoundry-cli@v7.1.0+incompatible/actor/v2action/service_plan_visibility_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 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 ) 13 14 var _ = Describe("Service Plan Visibility Actions", func() { 15 var ( 16 actor *Actor 17 fakeCloudControllerClient *v2actionfakes.FakeCloudControllerClient 18 ) 19 20 BeforeEach(func() { 21 fakeCloudControllerClient = new(v2actionfakes.FakeCloudControllerClient) 22 actor = NewActor(fakeCloudControllerClient, nil, nil) 23 }) 24 25 Describe("GetServicePlanVisibilities", func() { 26 var ( 27 visibilities []ServicePlanVisibility 28 warnings Warnings 29 err error 30 ) 31 32 BeforeEach(func() { 33 fakeCloudControllerClient.GetServicePlanVisibilitiesReturns([]ccv2.ServicePlanVisibility{ 34 {GUID: "guid-1", ServicePlanGUID: "plan-guid-1", OrganizationGUID: "org-guid-1"}, 35 {GUID: "guid-2", ServicePlanGUID: "plan-guid-2", OrganizationGUID: "org-guid-2"}, 36 }, ccv2.Warnings{"cc-warning"}, nil) 37 }) 38 39 JustBeforeEach(func() { 40 visibilities, warnings, err = actor.GetServicePlanVisibilities("some-service-plan-guid") 41 }) 42 43 It("doesn't error", func() { 44 Expect(err).NotTo(HaveOccurred()) 45 }) 46 47 It("fetches visibilities from the cloud controller client, filtering by plan GUID", func() { 48 Expect(fakeCloudControllerClient.GetServicePlanVisibilitiesCallCount()).NotTo(BeZero()) 49 expectedFilters := []ccv2.Filter{ 50 { 51 Type: constant.ServicePlanGUIDFilter, 52 Operator: constant.EqualOperator, 53 Values: []string{"some-service-plan-guid"}, 54 }, 55 } 56 Expect(fakeCloudControllerClient.GetServicePlanVisibilitiesArgsForCall(0)).To(Equal(expectedFilters)) 57 }) 58 59 It("returns visibilities fetched from the cloud controller client", func() { 60 expectedVisibilities := []ServicePlanVisibility{ 61 {GUID: "guid-1", ServicePlanGUID: "plan-guid-1", OrganizationGUID: "org-guid-1"}, 62 {GUID: "guid-2", ServicePlanGUID: "plan-guid-2", OrganizationGUID: "org-guid-2"}, 63 } 64 Expect(visibilities).To(Equal(expectedVisibilities)) 65 }) 66 67 It("returns any warnings from the cloud controller client", func() { 68 Expect(warnings).To(ConsistOf("cc-warning")) 69 }) 70 71 When("fetching visibilities from the cloud controller client returns an error", func() { 72 BeforeEach(func() { 73 fakeCloudControllerClient.GetServicePlanVisibilitiesReturns(nil, ccv2.Warnings{"cc-warning"}, errors.New("boom")) 74 }) 75 76 It("propagates the error", func() { 77 Expect(err).To(MatchError("boom")) 78 }) 79 }) 80 81 It("returns any warnings from the cloud controller client", func() { 82 Expect(warnings).To(ConsistOf("cc-warning")) 83 }) 84 }) 85 })