Skip to content

Commit dfe2201

Browse files
authored
Make cups command idempotent (#3288)
1 parent ad2f7f4 commit dfe2201

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

command/v7/create_user_provided_service_command.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package v7
22

33
import (
4+
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
45
"code.cloudfoundry.org/cli/command"
56
"code.cloudfoundry.org/cli/command/flag"
67
"code.cloudfoundry.org/cli/resources"
@@ -43,7 +44,16 @@ func (cmd CreateUserProvidedServiceCommand) Execute(args []string) error {
4344

4445
warnings, err := cmd.Actor.CreateUserProvidedServiceInstance(serviceInstance)
4546
cmd.UI.DisplayWarnings(warnings)
46-
if err != nil {
47+
switch err.(type) {
48+
case nil:
49+
case ccerror.ServiceInstanceNameTakenError:
50+
cmd.UI.DisplayTextWithFlavor("Service instance {{.ServiceInstanceName}} already exists",
51+
map[string]interface{}{
52+
"ServiceInstanceName": serviceInstance.Name,
53+
})
54+
cmd.UI.DisplayOK()
55+
return nil
56+
default:
4757
return err
4858
}
4959

command/v7/create_user_provided_service_command_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package v7_test
33
import (
44
"errors"
55

6+
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
67
"code.cloudfoundry.org/cli/types"
78

89
"code.cloudfoundry.org/cli/actor/v7action"
@@ -215,5 +216,20 @@ var _ = Describe("create-user-provided-service Command", func() {
215216
))
216217
})
217218
})
219+
220+
When("the service instance name is taken", func() {
221+
BeforeEach(func() {
222+
fakeActor.CreateUserProvidedServiceInstanceReturns(
223+
nil,
224+
ccerror.ServiceInstanceNameTakenError{},
225+
)
226+
})
227+
228+
It("succeeds, displaying warnings, 'OK' and an informative message", func() {
229+
Expect(executeErr).NotTo(HaveOccurred())
230+
Expect(testUI.Out).To(Say("Service instance %s already exists", fakeServiceInstanceName))
231+
Expect(testUI.Out).To(Say("OK"))
232+
})
233+
})
218234
})
219235
})

0 commit comments

Comments
 (0)