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