-
Notifications
You must be signed in to change notification settings - Fork 933
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
service: --params flag retrieves service instance params #2141
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
18bffc2
service: --params flag retrieves service instance params
FelisiaM 7061d71
Added ServiceInstanceParametersFetchNotSupportedError
FelisiaM d91ea43
Remove test focus
FelisiaM fb7b3e4
Error when params not retriavable
FelisiaM 0e43f17
Address PR feedback
FelisiaM d954c1b
v8(services): simplify code to display service
blgm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -73,12 +73,6 @@ var _ = Describe("Service Instance Details Action", func() { | |
nil, | ||
) | ||
|
||
fakeCloudControllerClient.GetServiceInstanceParametersReturns( | ||
types.JSONObject{"foo": "bar"}, | ||
ccv3.Warnings{"some-parameters-warning"}, | ||
nil, | ||
) | ||
|
||
fakeCloudControllerClient.GetFeatureFlagReturns( | ||
resources.FeatureFlag{Name: "service_instance_sharing", Enabled: true}, | ||
ccv3.Warnings{}, | ||
|
@@ -129,7 +123,6 @@ var _ = Describe("Service Instance Details Action", func() { | |
Expect(executionError).NotTo(HaveOccurred()) | ||
Expect(warnings).To(ConsistOf( | ||
"some-service-instance-warning", | ||
"some-parameters-warning", | ||
"some-bindings-warning", | ||
)) | ||
}) | ||
|
@@ -155,9 +148,7 @@ var _ = Describe("Service Instance Details Action", func() { | |
ServicePlan: resources.ServicePlan{Name: servicePlanName}, | ||
ServiceBrokerName: serviceBrokerName, | ||
SharedStatus: SharedStatus{}, | ||
Parameters: ServiceInstanceParameters{ | ||
Value: types.JSONObject{"foo": "bar"}, | ||
}, | ||
Parameters: ServiceInstanceParameters{}, | ||
BoundApps: []resources.ServiceCredentialBinding{ | ||
{ | ||
Type: resources.AppBinding, | ||
|
@@ -263,53 +254,6 @@ var _ = Describe("Service Instance Details Action", func() { | |
}) | ||
}) | ||
|
||
Describe("getting the parameters", func() { | ||
It("makes the correct call to get the parameters", func() { | ||
Expect(fakeCloudControllerClient.GetServiceInstanceParametersCallCount()).To(Equal(1)) | ||
Expect(fakeCloudControllerClient.GetServiceInstanceParametersArgsForCall(0)).To(Equal(serviceInstanceGUID)) | ||
}) | ||
|
||
When("getting the parameters fails with an expected error", func() { | ||
BeforeEach(func() { | ||
fakeCloudControllerClient.GetServiceInstanceParametersReturns( | ||
types.JSONObject{}, | ||
ccv3.Warnings{"some-parameters-warning"}, | ||
ccerror.V3UnexpectedResponseError{ | ||
V3ErrorResponse: ccerror.V3ErrorResponse{ | ||
Errors: []ccerror.V3Error{{ | ||
Code: 1234, | ||
Detail: "cannot get parameters reason", | ||
Title: "CF-SomeRandomError", | ||
}}, | ||
}, | ||
}, | ||
) | ||
}) | ||
|
||
It("does not return an error, but returns warnings and the reason", func() { | ||
Expect(executionError).NotTo(HaveOccurred()) | ||
Expect(warnings).To(ContainElement("some-parameters-warning")) | ||
Expect(serviceInstance.Parameters.MissingReason).To(Equal("cannot get parameters reason")) | ||
}) | ||
}) | ||
|
||
When("getting the parameters fails with an another error", func() { | ||
BeforeEach(func() { | ||
fakeCloudControllerClient.GetServiceInstanceParametersReturns( | ||
types.JSONObject{}, | ||
ccv3.Warnings{"some-parameters-warning"}, | ||
errors.New("not expected"), | ||
) | ||
}) | ||
|
||
It("does not return an error, but returns warnings and the reason", func() { | ||
Expect(executionError).NotTo(HaveOccurred()) | ||
Expect(warnings).To(ContainElement("some-parameters-warning")) | ||
Expect(serviceInstance.Parameters.MissingReason).To(Equal("not expected")) | ||
}) | ||
}) | ||
}) | ||
|
||
Describe("sharing", func() { | ||
When("targeting originating service instance space", func() { | ||
When("the service instance has shared spaces", func() { | ||
|
@@ -467,7 +411,7 @@ var _ = Describe("Service Instance Details Action", func() { | |
It("returns an empty service instance, warnings, and the error", func() { | ||
Expect(serviceInstance).To(Equal(ServiceInstanceDetails{})) | ||
Expect(executionError).To(MatchError("error getting feature flag")) | ||
Expect(warnings).To(ConsistOf("some-service-instance-warning", "some-parameters-warning", warningMessage)) | ||
Expect(warnings).To(ConsistOf("some-service-instance-warning", warningMessage)) | ||
}) | ||
}) | ||
|
||
|
@@ -485,7 +429,7 @@ var _ = Describe("Service Instance Details Action", func() { | |
It("returns an empty service instance, warnings, and the error", func() { | ||
Expect(serviceInstance).To(Equal(ServiceInstanceDetails{})) | ||
Expect(executionError).To(MatchError("error getting offering")) | ||
Expect(warnings).To(ConsistOf("some-service-instance-warning", "some-parameters-warning", warningMessage)) | ||
Expect(warnings).To(ConsistOf("some-service-instance-warning", warningMessage)) | ||
}) | ||
}) | ||
|
||
|
@@ -518,7 +462,7 @@ var _ = Describe("Service Instance Details Action", func() { | |
It("returns an empty service instance, warnings, and the error", func() { | ||
Expect(serviceInstance).To(Equal(ServiceInstanceDetails{})) | ||
Expect(executionError).To(MatchError("no service instance")) | ||
Expect(warnings).To(ConsistOf("some-service-instance-warning", "some-parameters-warning", warningMessage)) | ||
Expect(warnings).To(ConsistOf("some-service-instance-warning", warningMessage)) | ||
}) | ||
}) | ||
|
||
|
@@ -542,7 +486,7 @@ var _ = Describe("Service Instance Details Action", func() { | |
It("returns an empty service instance, warnings, and the error", func() { | ||
Expect(serviceInstance).To(Equal(ServiceInstanceDetails{})) | ||
Expect(executionError).To(MatchError("no service instance")) | ||
Expect(warnings).To(ConsistOf("some-service-instance-warning", "some-parameters-warning", warningMessage)) | ||
Expect(warnings).To(ConsistOf("some-service-instance-warning", warningMessage)) | ||
}) | ||
}) | ||
|
||
|
@@ -764,4 +708,184 @@ var _ = Describe("Service Instance Details Action", func() { | |
}) | ||
}) | ||
}) | ||
|
||
Describe("GetServiceInstanceParameters", func() { | ||
const ( | ||
serviceInstanceName = "some-service-instance-name" | ||
serviceInstanceGUID = "some-service-instance-guid" | ||
spaceGUID = "some-source-space-guid" | ||
) | ||
|
||
var ( | ||
serviceInstance ServiceInstanceDetails | ||
warnings Warnings | ||
executionError error | ||
) | ||
|
||
BeforeEach(func() { | ||
fakeCloudControllerClient.GetServiceInstanceByNameAndSpaceReturns( | ||
resources.ServiceInstance{ | ||
Type: resources.ManagedServiceInstance, | ||
Name: serviceInstanceName, | ||
GUID: serviceInstanceGUID, | ||
SpaceGUID: spaceGUID, | ||
}, | ||
ccv3.IncludedResources{}, | ||
ccv3.Warnings{"some-service-instance-warning"}, | ||
nil, | ||
) | ||
|
||
fakeCloudControllerClient.GetServiceInstanceParametersReturns( | ||
types.JSONObject{"foo": "bar"}, | ||
ccv3.Warnings{"some-parameters-warning"}, | ||
nil, | ||
) | ||
|
||
}) | ||
|
||
JustBeforeEach(func() { | ||
serviceInstance, warnings, executionError = actor.GetServiceInstanceParameters(serviceInstanceName, spaceGUID) | ||
}) | ||
|
||
Describe("getting the service instance", func() { | ||
It("makes the correct call to get the service instance", func() { | ||
Expect(fakeCloudControllerClient.GetServiceInstanceByNameAndSpaceCallCount()).To(Equal(1)) | ||
actualName, actualSpaceGUID, actualQuery := fakeCloudControllerClient.GetServiceInstanceByNameAndSpaceArgsForCall(0) | ||
Expect(actualName).To(Equal(serviceInstanceName)) | ||
Expect(actualSpaceGUID).To(Equal(spaceGUID)) | ||
Expect(actualQuery).To(BeNil()) | ||
}) | ||
|
||
When("the service instance cannot be found", func() { | ||
BeforeEach(func() { | ||
fakeCloudControllerClient.GetServiceInstanceByNameAndSpaceReturns( | ||
resources.ServiceInstance{}, | ||
ccv3.IncludedResources{}, | ||
ccv3.Warnings{}, | ||
ccerror.ServiceInstanceNotFoundError{Name: serviceInstanceName}, | ||
) | ||
}) | ||
|
||
It("returns an error and warnings", func() { | ||
Expect(executionError).To(MatchError(actionerror.ServiceInstanceNotFoundError{Name: serviceInstanceName})) | ||
}) | ||
|
||
It("does not attempt any other requests", func() { | ||
Expect(fakeCloudControllerClient.GetServiceInstanceParametersCallCount()).To(Equal(0)) | ||
Expect(fakeCloudControllerClient.GetFeatureFlagCallCount()).To(Equal(0)) | ||
Expect(fakeCloudControllerClient.GetServiceOfferingByGUIDCallCount()).To(Equal(0)) | ||
Expect(fakeCloudControllerClient.GetServiceInstanceSharedSpacesCallCount()).To(Equal(0)) | ||
Expect(fakeCloudControllerClient.GetServicePlanByGUIDCallCount()).To(Equal(0)) | ||
Expect(fakeCloudControllerClient.GetServiceCredentialBindingsCallCount()).To(Equal(0)) | ||
}) | ||
}) | ||
|
||
When("getting the service instance returns an error", func() { | ||
BeforeEach(func() { | ||
fakeCloudControllerClient.GetServiceInstanceByNameAndSpaceReturns( | ||
resources.ServiceInstance{}, | ||
ccv3.IncludedResources{}, | ||
ccv3.Warnings{"some-service-instance-warning"}, | ||
errors.New("no service instance")) | ||
}) | ||
|
||
It("returns an error and warnings", func() { | ||
Expect(executionError).To(MatchError("no service instance")) | ||
Expect(warnings).To(ConsistOf("some-service-instance-warning")) | ||
}) | ||
|
||
It("does not attempt any other requests", func() { | ||
Expect(fakeCloudControllerClient.GetServiceInstanceParametersCallCount()).To(Equal(0)) | ||
Expect(fakeCloudControllerClient.GetFeatureFlagCallCount()).To(Equal(0)) | ||
Expect(fakeCloudControllerClient.GetServiceOfferingByGUIDCallCount()).To(Equal(0)) | ||
Expect(fakeCloudControllerClient.GetServiceInstanceSharedSpacesCallCount()).To(Equal(0)) | ||
Expect(fakeCloudControllerClient.GetServicePlanByGUIDCallCount()).To(Equal(0)) | ||
Expect(fakeCloudControllerClient.GetServiceCredentialBindingsCallCount()).To(Equal(0)) | ||
}) | ||
}) | ||
}) | ||
|
||
Describe("getting the parameters", func() { | ||
It("makes the correct call to get the parameters", func() { | ||
Expect(fakeCloudControllerClient.GetServiceInstanceParametersCallCount()).To(Equal(1)) | ||
Expect(fakeCloudControllerClient.GetServiceInstanceParametersArgsForCall(0)).To(Equal(serviceInstanceGUID)) | ||
}) | ||
|
||
When("getting the parameters fails with a V3UnexpectedResponseError", func() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should have a specific code path for a |
||
BeforeEach(func() { | ||
fakeCloudControllerClient.GetServiceInstanceParametersReturns( | ||
types.JSONObject{}, | ||
ccv3.Warnings{"some-parameters-warning"}, | ||
ccerror.V3UnexpectedResponseError{ | ||
V3ErrorResponse: ccerror.V3ErrorResponse{ | ||
Errors: []ccerror.V3Error{{ | ||
Code: 1234, | ||
Detail: "cannot get parameters reason", | ||
Title: "CF-SomeRandomError", | ||
}}, | ||
}, | ||
}, | ||
) | ||
}) | ||
|
||
It("does not return an error, but returns warnings and the reason", func() { | ||
Expect(executionError).NotTo(HaveOccurred()) | ||
Expect(warnings).To(ContainElement("some-parameters-warning")) | ||
Expect(serviceInstance.Parameters.MissingReason).To(Equal("cannot get parameters reason")) | ||
}) | ||
}) | ||
|
||
When("getting the parameters fails with a ServiceInstanceParametersFetchNotSupportedError", func() { | ||
BeforeEach(func() { | ||
fakeCloudControllerClient.GetServiceInstanceParametersReturns( | ||
types.JSONObject{}, | ||
ccv3.Warnings{"some-parameters-warning"}, | ||
ccerror.ServiceInstanceParametersFetchNotSupportedError{ | ||
Message: "This service does not support fetching service instance parameters.", | ||
}, | ||
) | ||
}) | ||
|
||
It("does not return an error, but returns warnings and the reason", func() { | ||
Expect(executionError).NotTo(HaveOccurred()) | ||
Expect(warnings).To(ContainElement("some-parameters-warning")) | ||
Expect(serviceInstance.Parameters.MissingReason).To(Equal("This service does not support fetching service instance parameters.")) | ||
}) | ||
}) | ||
|
||
When("getting the parameters fails with a ResourceNotFoundError", func() { | ||
BeforeEach(func() { | ||
fakeCloudControllerClient.GetServiceInstanceParametersReturns( | ||
types.JSONObject{}, | ||
ccv3.Warnings{"some-parameters-warning"}, | ||
ccerror.ResourceNotFoundError{ | ||
Message: "Service instance not found", | ||
}, | ||
) | ||
}) | ||
|
||
It("converts the error to fetching not supported", func() { | ||
Expect(executionError).NotTo(HaveOccurred()) | ||
Expect(warnings).To(ContainElement("some-parameters-warning")) | ||
Expect(serviceInstance.Parameters.MissingReason).To(Equal("This service does not support fetching service instance parameters.")) | ||
}) | ||
}) | ||
|
||
When("getting the parameters fails with an another error", func() { | ||
BeforeEach(func() { | ||
fakeCloudControllerClient.GetServiceInstanceParametersReturns( | ||
types.JSONObject{}, | ||
ccv3.Warnings{"some-parameters-warning"}, | ||
errors.New("not expected"), | ||
) | ||
}) | ||
|
||
It("does not return an error, but returns warnings and the reason", func() { | ||
Expect(executionError).NotTo(HaveOccurred()) | ||
Expect(warnings).To(ContainElement("some-parameters-warning")) | ||
Expect(serviceInstance.Parameters.MissingReason).To(Equal("not expected")) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
12 changes: 12 additions & 0 deletions
12
api/cloudcontroller/ccerror/service_instance_parameters_fetch_not_supported_error.go
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,12 @@ | ||
package ccerror | ||
|
||
// ServiceInstanceParametersFetchNotSupportedError is returned when | ||
// the service instance is user-provided or | ||
// service instance fetching is not supported for managed instances | ||
type ServiceInstanceParametersFetchNotSupportedError struct { | ||
Message string | ||
} | ||
|
||
func (e ServiceInstanceParametersFetchNotSupportedError) Error() string { | ||
return e.Message | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like a
GetServiceInstanceParameters()
function should returnServiceInstanceParameters
rather thanServiceInstanceDetails