diff --git a/command/v7/create_user_provided_service_command.go b/command/v7/create_user_provided_service_command.go index fbe7a412bda..7b6b5fc27c7 100644 --- a/command/v7/create_user_provided_service_command.go +++ b/command/v7/create_user_provided_service_command.go @@ -1,6 +1,7 @@ package v7 import ( + "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" "code.cloudfoundry.org/cli/command" "code.cloudfoundry.org/cli/command/flag" "code.cloudfoundry.org/cli/resources" @@ -43,7 +44,16 @@ func (cmd CreateUserProvidedServiceCommand) Execute(args []string) error { warnings, err := cmd.Actor.CreateUserProvidedServiceInstance(serviceInstance) cmd.UI.DisplayWarnings(warnings) - if err != nil { + switch err.(type) { + case nil: + case ccerror.ServiceInstanceNameTakenError: + cmd.UI.DisplayTextWithFlavor("Service instance {{.ServiceInstanceName}} already exists", + map[string]interface{}{ + "ServiceInstanceName": serviceInstance.Name, + }) + cmd.UI.DisplayOK() + return nil + default: return err } diff --git a/command/v7/create_user_provided_service_command_test.go b/command/v7/create_user_provided_service_command_test.go index bccc37e67fd..c63c24c86d6 100644 --- a/command/v7/create_user_provided_service_command_test.go +++ b/command/v7/create_user_provided_service_command_test.go @@ -3,6 +3,7 @@ package v7_test import ( "errors" + "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" "code.cloudfoundry.org/cli/types" "code.cloudfoundry.org/cli/actor/v7action" @@ -215,5 +216,20 @@ var _ = Describe("create-user-provided-service Command", func() { )) }) }) + + When("the service instance name is taken", func() { + BeforeEach(func() { + fakeActor.CreateUserProvidedServiceInstanceReturns( + nil, + ccerror.ServiceInstanceNameTakenError{}, + ) + }) + + It("succeeds, displaying warnings, 'OK' and an informative message", func() { + Expect(executeErr).NotTo(HaveOccurred()) + Expect(testUI.Out).To(Say("Service instance %s already exists", fakeServiceInstanceName)) + Expect(testUI.Out).To(Say("OK")) + }) + }) }) })