From b102059dedcf946215cd730923285c10f7477ba2 Mon Sep 17 00:00:00 2001 From: Shwetha Gururaj Date: Mon, 4 Nov 2024 16:19:15 -0500 Subject: [PATCH] test --- command/v7/create_service_command.go | 2 +- command/v7/create_service_command_test.go | 2 +- .../v7/create_user_provided_service_command.go | 12 +++++++++++- .../create_user_provided_service_command_test.go | 16 ++++++++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/command/v7/create_service_command.go b/command/v7/create_service_command.go index ee10e723bba..a0af6ec5e2c 100644 --- a/command/v7/create_service_command.go +++ b/command/v7/create_service_command.go @@ -87,8 +87,8 @@ func (cmd CreateServiceCommand) Execute(args []string) error { switch err.(type) { case nil: case ccerror.ServiceInstanceNameTakenError: - cmd.UI.DisplayOK() cmd.UI.DisplayTextWithFlavor("Service instance {{.ServiceInstanceName}} already exists", cmd.serviceInstanceName()) + cmd.UI.DisplayOK() return nil default: return err diff --git a/command/v7/create_service_command_test.go b/command/v7/create_service_command_test.go index a0686309003..4078c5eb0c6 100644 --- a/command/v7/create_service_command_test.go +++ b/command/v7/create_service_command_test.go @@ -339,8 +339,8 @@ var _ = Describe("create-service Command", func() { Expect(testUI.Err).To(Say("a-warning")) Expect(testUI.Err).To(Say("another-warning")) - Expect(testUI.Out).To(Say("OK")) Expect(testUI.Out).To(Say("Service instance %s already exists", requestedServiceInstanceName)) + Expect(testUI.Out).To(Say("OK")) }) }) }) 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")) + }) + }) }) })