-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Present included resources in includes resolver
Included resources in the API response should be in the same format the API would return them when getting them. This change makes the include resolver delegate to a presenter that in turn delegates to the included object presenter This fixes service broker names not being visible in `cf marketplace`
- Loading branch information
1 parent
d3f479b
commit 5282111
Showing
6 changed files
with
259 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package presenter | ||
|
||
import ( | ||
"net/url" | ||
|
||
"code.cloudfoundry.org/korifi/api/repositories" | ||
"code.cloudfoundry.org/korifi/api/repositories/relationships" | ||
) | ||
|
||
type Resource struct { | ||
serverURL url.URL | ||
} | ||
|
||
func NewResource(serverURL url.URL) *Resource { | ||
return &Resource{ | ||
serverURL: serverURL, | ||
} | ||
} | ||
|
||
func (r *Resource) PresentResource(resource relationships.Resource) any { | ||
switch res := resource.(type) { | ||
case repositories.ServiceBrokerRecord: | ||
return ForServiceBroker(res, r.serverURL) | ||
case repositories.ServiceOfferingRecord: | ||
return ForServiceOffering(res, r.serverURL) | ||
case repositories.ServicePlanRecord: | ||
return ForServicePlan(res, r.serverURL) | ||
default: | ||
return resource | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package presenter_test | ||
|
||
import ( | ||
"net/url" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"code.cloudfoundry.org/korifi/api/presenter" | ||
"code.cloudfoundry.org/korifi/api/repositories" | ||
"code.cloudfoundry.org/korifi/api/repositories/relationships" | ||
"code.cloudfoundry.org/korifi/model" | ||
) | ||
|
||
type unsupportedResource struct{} | ||
|
||
func (r *unsupportedResource) Relationships() map[string]model.ToOneRelationship { | ||
return nil | ||
} | ||
|
||
var _ = Describe("Resource", func() { | ||
var ( | ||
resourcePresenter *presenter.Resource | ||
resource relationships.Resource | ||
presentedResource any | ||
) | ||
|
||
BeforeEach(func() { | ||
url, err := url.Parse("https://api.example.org") | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
resource = &unsupportedResource{} | ||
resourcePresenter = presenter.NewResource(*url) | ||
}) | ||
|
||
JustBeforeEach(func() { | ||
presentedResource = resourcePresenter.PresentResource(resource) | ||
}) | ||
|
||
It("returns the original resource", func() { | ||
Expect(presentedResource).To(BeAssignableToTypeOf(&unsupportedResource{})) | ||
}) | ||
|
||
When("the resource is a service broker", func() { | ||
BeforeEach(func() { | ||
resource = repositories.ServiceBrokerRecord{} | ||
}) | ||
|
||
It("returns presented broker", func() { | ||
Expect(presentedResource).To(BeAssignableToTypeOf(presenter.ServiceBrokerResponse{})) | ||
}) | ||
}) | ||
|
||
When("the resource is a service offering", func() { | ||
BeforeEach(func() { | ||
resource = repositories.ServiceOfferingRecord{} | ||
}) | ||
|
||
It("returns presented broker", func() { | ||
Expect(presentedResource).To(BeAssignableToTypeOf(presenter.ServiceOfferingResponse{})) | ||
}) | ||
}) | ||
|
||
When("the resource is a service plan", func() { | ||
BeforeEach(func() { | ||
resource = repositories.ServicePlanRecord{} | ||
}) | ||
|
||
It("returns presented broker", func() { | ||
Expect(presentedResource).To(BeAssignableToTypeOf(presenter.ServicePlanResponse{})) | ||
}) | ||
}) | ||
}) |