Skip to content

Commit

Permalink
private domain doesn't fail when domain already exists (#2609)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Fuller committed Oct 12, 2023
1 parent ec2920f commit 7469d0a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions command/v7/create_private_domain_command.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package v7

import (
"fmt"

"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
"code.cloudfoundry.org/cli/command/flag"
)

Expand Down Expand Up @@ -34,8 +37,17 @@ func (cmd CreatePrivateDomainCommand) Execute(args []string) error {
})

warnings, err := cmd.Actor.CreatePrivateDomain(domain, orgName)

cmd.UI.DisplayWarnings(warnings)
if err != nil {
if e, ok := err.(ccerror.UnprocessableEntityError); ok {
inUse := fmt.Sprintf("The domain name \"%s\" is already in use", domain)
if e.Message == inUse {
cmd.UI.DisplayWarning(err.Error())
cmd.UI.DisplayOK()
return nil
}
}
return err
}

Expand Down
6 changes: 3 additions & 3 deletions integration/v7/isolated/create_private_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ var _ = Describe("create-private-domain command", func() {
privateDomain1 = helpers.NewDomain(orgName, helpers.NewDomainName())
privateDomain1.Create()
})
It("should fail and return an error", func() {
It("succeeds", func() {
session := helpers.CF("create-private-domain", orgName, privateDomain1.Name)

Eventually(session.Err).Should(Say("The domain name \"%s\" is already in use", privateDomain1.Name))
Eventually(session).Should(Say("FAILED"))
Eventually(session).Should(Exit(1))
Eventually(session).Should(Say("OK"))
Eventually(session).Should(Exit(0))
})
})
})
Expand Down

0 comments on commit 7469d0a

Please sign in to comment.