Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
gururajsh committed Nov 4, 2024
1 parent d724fb7 commit b102059
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion command/v7/create_service_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion command/v7/create_service_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})
})
})
Expand Down
12 changes: 11 additions & 1 deletion command/v7/create_user_provided_service_command.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
16 changes: 16 additions & 0 deletions command/v7/create_user_provided_service_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"))
})
})
})
})

0 comments on commit b102059

Please sign in to comment.