Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose api errors for service broker commands #465

Merged
merged 1 commit into from
Jun 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cf/api/service_brokers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (repo CloudControllerServiceBrokerRepository) FindByName(name string) (serv
return false
})

if !foundBroker {
if !foundBroker && (apiErr == nil) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, since you have now added another variable to the conditional, I expected at least two more tests or really four totals: foundBroker and apiErr nil, foundBroker and apiErr not nil, !foundBroker and apiErr nil, and !foundBroker and apiErr not nil.

Are you compacting the tests or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the test coverage is sufficient; there's no case where we'd have a list of service brokers to search as well as an apiErr from CC. If we get a CC error, we return from ListPaginatedResources before ever searching for a potential service broker. foundBroker will always remain false if there's a CC error.

This block covers a weird case: the CC may return 200 with an empty list, so we make our own error in this if-block. The additional check is a bug fix; the previous behavior was ignoring existing CC errors and would overwrite them with the ModelNotFoundError.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, OK. I guess I'd then simplify the conditional into two. However, we are splitting hair here so if others are OK then I am happy to be cool with it. Cheers.

apiErr = errors.NewModelNotFoundError("Service Broker", name)
}

Expand Down
21 changes: 21 additions & 0 deletions cf/api/service_brokers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,27 @@ var _ = Describe("Service Brokers Repo", func() {
Expect(apiErr).To(HaveOccurred())
Expect(apiErr.Error()).To(Equal("Service Broker my-broker not found"))
})

It("returns an error when listing service brokers returns an api error", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description reads odd... "returns... returns..."

req := testapi.NewCloudControllerTestRequest(testnet.TestRequest{
Method: "GET",
Path: "/v2/service_brokers?q=name%3Amy-broker",
Response: testnet.TestResponse{Status: http.StatusForbidden, Body: `{
"code": 10003,
"description": "You are not authorized to perform the requested action",
"error_code": "CF-NotAuthorized"
}`},
})

ts, handler, repo := createServiceBrokerRepo(req)
defer ts.Close()

_, apiErr := repo.FindByName("my-broker")

Expect(handler).To(HaveAllRequestsCalled())
Expect(apiErr).To(HaveOccurred())
Expect(apiErr.Error()).To(Equal("Server error, status code: 403, error code: 10003, message: You are not authorized to perform the requested action"))
})
})

Describe("FindByGuid", func() {
Expand Down