github.com/willmadison/cli@v6.40.1-0.20181018160101-29d5937903ff+incompatible/api/cloudcontroller/ccv2/service_plan_visibility_test.go (about) 1 package ccv2_test 2 3 import ( 4 "net/http" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 7 . "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/ghttp" 12 ) 13 14 var _ = Describe("Service Plan Visibility", func() { 15 var client *Client 16 17 BeforeEach(func() { 18 client = NewTestClient() 19 }) 20 21 Describe("GetServicePlanVisibilities", func() { 22 var ( 23 visibilities []ServicePlanVisibility 24 warnings Warnings 25 executeErr error 26 ) 27 28 JustBeforeEach(func() { 29 visibilities, warnings, executeErr = client.GetServicePlanVisibilities(Filter{ 30 Type: constant.OrganizationGUIDFilter, 31 Operator: constant.EqualOperator, 32 Values: []string{"some-org-guid"}, 33 }) 34 }) 35 36 When("the cc returns back service brokers", func() { 37 BeforeEach(func() { 38 response1 := `{ 39 "next_url": "/v2/service_plan_visibilities?q=organization_guid:some-org-guid&page=2", 40 "resources": [ 41 { 42 "metadata": { 43 "guid": "some-visibility-guid-1" 44 }, 45 "entity": { 46 "service_plan_guid": "some-service-plan-guid-1", 47 "organization_guid": "some-org-guid" 48 } 49 }, 50 { 51 "metadata": { 52 "guid": "some-visibility-guid-2" 53 }, 54 "entity": { 55 "service_plan_guid": "some-service-plan-guid-2", 56 "organization_guid": "some-org-guid" 57 } 58 } 59 ] 60 }` 61 response2 := `{ 62 "next_url": null, 63 "resources": [ 64 { 65 "metadata": { 66 "guid": "some-visibility-guid-3" 67 }, 68 "entity": { 69 "service_plan_guid": "some-service-plan-guid-3", 70 "organization_guid": "some-org-guid" 71 } 72 }, 73 { 74 "metadata": { 75 "guid": "some-visibility-guid-4" 76 }, 77 "entity": { 78 "service_plan_guid": "some-service-plan-guid-4", 79 "organization_guid": "some-org-guid" 80 } 81 } 82 ] 83 }` 84 server.AppendHandlers( 85 CombineHandlers( 86 VerifyRequest(http.MethodGet, "/v2/service_plan_visibilities", "q=organization_guid:some-org-guid"), 87 RespondWith(http.StatusOK, response1, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 88 ), 89 ) 90 server.AppendHandlers( 91 CombineHandlers( 92 VerifyRequest(http.MethodGet, "/v2/service_plan_visibilities", "q=organization_guid:some-org-guid&page=2"), 93 RespondWith(http.StatusOK, response2, http.Header{"X-Cf-Warnings": {"this is another warning"}}), 94 ), 95 ) 96 }) 97 98 It("returns all the queried service brokers", func() { 99 Expect(executeErr).NotTo(HaveOccurred()) 100 Expect(visibilities).To(ConsistOf([]ServicePlanVisibility{ 101 {GUID: "some-visibility-guid-1", OrganizationGUID: "some-org-guid", ServicePlanGUID: "some-service-plan-guid-1"}, 102 {GUID: "some-visibility-guid-2", OrganizationGUID: "some-org-guid", ServicePlanGUID: "some-service-plan-guid-2"}, 103 {GUID: "some-visibility-guid-3", OrganizationGUID: "some-org-guid", ServicePlanGUID: "some-service-plan-guid-3"}, 104 {GUID: "some-visibility-guid-4", OrganizationGUID: "some-org-guid", ServicePlanGUID: "some-service-plan-guid-4"}, 105 })) 106 Expect(warnings).To(ConsistOf(Warnings{"this is a warning", "this is another warning"})) 107 }) 108 }) 109 110 When("the cc returns an error", func() { 111 BeforeEach(func() { 112 response := `{ 113 "description": "The broker is broken.", 114 "error_code": "CF-BrokenBroker", 115 "code": 90003 116 }` 117 server.AppendHandlers( 118 CombineHandlers( 119 VerifyRequest(http.MethodGet, "/v2/service_plan_visibilities"), 120 RespondWith(http.StatusTeapot, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 121 ), 122 ) 123 }) 124 125 It("returns an error and warnings", func() { 126 Expect(executeErr).To(MatchError(ccerror.V2UnexpectedResponseError{ 127 V2ErrorResponse: ccerror.V2ErrorResponse{ 128 Code: 90003, 129 Description: "The broker is broken.", 130 ErrorCode: "CF-BrokenBroker", 131 }, 132 ResponseCode: http.StatusTeapot, 133 })) 134 Expect(warnings).To(ConsistOf("this is a warning")) 135 }) 136 }) 137 }) 138 })