Skip to content

Commit 42c250a

Browse files
klapkovgeorgethebeatle
authored andcommitted
Add GET v3/service_brokers/:guid
1 parent 83bb40d commit 42c250a

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

api/handlers/service_broker.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ func (h *ServiceBroker) list(r *http.Request) (*routing.Response, error) {
8080
return routing.NewResponse(http.StatusOK).WithBody(presenter.ForList(presenter.ForServiceBroker, brokers, h.serverURL, *r.URL)), nil
8181
}
8282

83+
func (h *ServiceBroker) get(r *http.Request) (*routing.Response, error) {
84+
authInfo, _ := authorization.InfoFromContext(r.Context())
85+
logger := logr.FromContextOrDiscard(r.Context()).WithName("handlers.service-broker.list")
86+
87+
guid := routing.URLParam(r, "guid")
88+
broker, err := h.serviceBrokerRepo.GetServiceBroker(r.Context(), authInfo, guid)
89+
if err != nil {
90+
return nil, apierrors.LogAndReturn(logger, apierrors.ForbiddenAsNotFound(err), "failed to get service broker")
91+
}
92+
93+
return routing.NewResponse(http.StatusOK).WithBody(presenter.ForServiceBroker(broker, h.serverURL)), nil
94+
}
95+
8396
func (h *ServiceBroker) delete(r *http.Request) (*routing.Response, error) {
8497
authInfo, _ := authorization.InfoFromContext(r.Context())
8598
logger := logr.FromContextOrDiscard(r.Context()).WithName("handlers.service-broker.delete")
@@ -136,6 +149,7 @@ func (h *ServiceBroker) AuthenticatedRoutes() []routing.Route {
136149
return []routing.Route{
137150
{Method: "POST", Pattern: ServiceBrokersPath, Handler: h.create},
138151
{Method: "GET", Pattern: ServiceBrokersPath, Handler: h.list},
152+
{Method: "GET", Pattern: ServiceBrokerPath, Handler: h.get},
139153
{Method: "DELETE", Pattern: ServiceBrokerPath, Handler: h.delete},
140154
{Method: "PATCH", Pattern: ServiceBrokerPath, Handler: h.update},
141155
}

api/handlers/service_broker_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,52 @@ var _ = Describe("ServiceBroker", func() {
167167
})
168168
})
169169

170+
Describe("GET /v3/service_brokers/guid", func() {
171+
BeforeEach(func() {
172+
serviceBrokerRepo.GetServiceBrokerReturns(repositories.ServiceBrokerRecord{
173+
CFResource: model.CFResource{
174+
GUID: "broker-guid",
175+
},
176+
}, nil)
177+
178+
var err error
179+
req, err = http.NewRequestWithContext(ctx, "GET", "/v3/service_brokers/broker-guid", nil)
180+
Expect(err).NotTo(HaveOccurred())
181+
})
182+
183+
It("gets the service broker", func() {
184+
Expect(serviceBrokerRepo.GetServiceBrokerCallCount()).To(Equal(1))
185+
_, actualAuthInfo, actualBrokerGUID := serviceBrokerRepo.GetServiceBrokerArgsForCall(0)
186+
Expect(actualAuthInfo).To(Equal(authInfo))
187+
Expect(actualBrokerGUID).To(Equal("broker-guid"))
188+
189+
Expect(rr).To(HaveHTTPStatus(http.StatusOK))
190+
Expect(rr).To(HaveHTTPBody(SatisfyAll(
191+
MatchJSONPath("$.guid", "broker-guid"),
192+
)))
193+
})
194+
195+
When("getting the service broker is not allowed", func() {
196+
BeforeEach(func() {
197+
serviceBrokerRepo.GetServiceBrokerReturns(repositories.ServiceBrokerRecord{}, apierrors.NewForbiddenError(nil, repositories.ServiceBrokerResourceType))
198+
})
199+
200+
It("returns a not found error", func() {
201+
expectNotFoundError(repositories.ServiceBrokerResourceType)
202+
})
203+
})
204+
205+
When("getting the service broker fails with an error", func() {
206+
BeforeEach(func() {
207+
serviceBrokerRepo.GetServiceBrokerReturns(repositories.ServiceBrokerRecord{}, errors.New("get-broker-err"))
208+
})
209+
210+
It("returns an error", func() {
211+
expectUnknownError()
212+
})
213+
})
214+
})
215+
170216
Describe("DELETE /v3/service_brokers/guid", func() {
171217
BeforeEach(func() {
172218
serviceBrokerRepo.GetServiceBrokerReturns(repositories.ServiceBrokerRecord{

tests/e2e/service_brokers_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,31 @@ var _ = Describe("Service Brokers", func() {
8383
})
8484
})
8585

86+
Describe("Get", func() {
87+
var (
88+
result responseResource
89+
brokerGUID string
90+
)
91+
92+
BeforeEach(func() {
93+
brokerGUID = createBroker(serviceBrokerURL)
94+
})
95+
96+
AfterEach(func() {
97+
broker.NewCatalogDeleter(rootNamespace).ForBrokerGUID(brokerGUID).Delete()
98+
})
99+
100+
JustBeforeEach(func() {
101+
resp, err = adminClient.R().SetResult(&result).Get("/v3/service_brokers/" + brokerGUID)
102+
Expect(err).NotTo(HaveOccurred())
103+
})
104+
105+
It("returns the service broker", func() {
106+
Expect(resp).To(HaveRestyStatusCode(http.StatusOK))
107+
Expect(result.GUID).To(Equal(brokerGUID))
108+
})
109+
})
110+
86111
Describe("Update", func() {
87112
var brokerGUID string
88113

0 commit comments

Comments
 (0)