Skip to content

Commit

Permalink
New integration test and adjustments of other tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dariquest committed Jan 30, 2025
1 parent 5be9eba commit 3faf27d
Showing 6 changed files with 201 additions and 18 deletions.
9 changes: 4 additions & 5 deletions command/v7/update_route_command.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package v7

import (
"fmt"

"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
"code.cloudfoundry.org/cli/command"
@@ -66,11 +68,8 @@ func (cmd UpdateRouteCommand) Execute(args []string) error {
}

if cmd.Options == nil && cmd.RemoveOptions == nil {
cmd.UI.DisplayWarning("No options were specified for the update of the Route {{.URL}}",
map[string]interface{}{
"URL": route.URL,
})
return nil
return actionerror.RouteOptionSupportError{
ErrorText: fmt.Sprintf("No options were specified for the update of the Route %s", route.URL)}
}

if cmd.Options != nil {
5 changes: 3 additions & 2 deletions command/v7/update_route_command_test.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package v7_test

import (
"errors"
"fmt"
"strconv"

"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
@@ -187,9 +188,9 @@ var _ = Describe("update-route Command", func() {
cmd.RemoveOptions = nil
})
It("does not update a route giving the error message", func() {
Expect(executeErr).To(BeNil())
Expect(executeErr).To(MatchError(actionerror.RouteOptionSupportError{
ErrorText: fmt.Sprintf("No options were specified for the update of the Route %s", domain)}))
Expect(fakeActor.UpdateRouteCallCount()).To(Equal(0))
Expect(testUI.Err).To(Say("No options were specified for the update of the Route"))
})
})

8 changes: 5 additions & 3 deletions integration/v7/isolated/create_route_command_test.go
Original file line number Diff line number Diff line change
@@ -27,26 +27,28 @@ var _ = Describe("create-route command", func() {

Eventually(session).Should(Say(`USAGE:`))
Eventually(session).Should(Say(`Create an HTTP route:\n`))
Eventually(session).Should(Say(`cf create-route DOMAIN \[--hostname HOSTNAME\] \[--path PATH\]\n`))
Eventually(session).Should(Say(`cf create-route DOMAIN \[--hostname HOSTNAME\] \[--path PATH\] \[--option OPTION=VALUE\]\n`))
Eventually(session).Should(Say(`Create a TCP route:\n`))
Eventually(session).Should(Say(`cf create-route DOMAIN \[--port PORT\]\n`))
Eventually(session).Should(Say(`cf create-route DOMAIN \[--port PORT\] \[--option OPTION=VALUE\]\n`))
Eventually(session).Should(Say(`\n`))

Eventually(session).Should(Say(`EXAMPLES:`))
Eventually(session).Should(Say(`cf create-route example.com\s+# example.com`))
Eventually(session).Should(Say(`cf create-route example.com --hostname myapp\s+# myapp.example.com`))
Eventually(session).Should(Say(`cf create-route example.com --hostname myapp --path foo\s+# myapp.example.com/foo`))
Eventually(session).Should(Say(`cf create-route example.com --port 5000\s+# example.com:5000`))
Eventually(session).Should(Say(`cf create-route example.com --hostname myapp -o loadbalancing=least-connections\s+# myapp.example.com with a per-route option`))
Eventually(session).Should(Say(`\n`))

Eventually(session).Should(Say(`OPTIONS:`))
Eventually(session).Should(Say(`--hostname, -n\s+Hostname for the HTTP route \(required for shared domains\)`))
Eventually(session).Should(Say(`--path\s+Path for the HTTP route`))
Eventually(session).Should(Say(`--port\s+Port for the TCP route \(default: random port\)`))
Eventually(session).Should(Say(`--option, -o\s+Set the value of a per-route option`))
Eventually(session).Should(Say(`\n`))

Eventually(session).Should(Say(`SEE ALSO:`))
Eventually(session).Should(Say(`check-route, domains, map-route, routes, unmap-route`))
Eventually(session).Should(Say(`check-route, domains, map-route, routes, unmap-route, update-route`))

Eventually(session).Should(Exit(0))
})
16 changes: 9 additions & 7 deletions integration/v7/isolated/map_route_command_test.go
Original file line number Diff line number Diff line change
@@ -29,29 +29,31 @@ var _ = Describe("map-route command", func() {

Eventually(session).Should(Say(`USAGE:`))
Eventually(session).Should(Say(`Map an HTTP route:\n`))
Eventually(session).Should(Say(`cf map-route APP_NAME DOMAIN \[--hostname HOSTNAME\] \[--path PATH\] \[--app-protocol PROTOCOL\]\n`))
Eventually(session).Should(Say(`cf map-route APP_NAME DOMAIN \[--hostname HOSTNAME\] \[--path PATH\] \[--app-protocol PROTOCOL\] \[--option OPTION=VALUE\]\n`))
Eventually(session).Should(Say(`Map a TCP route:\n`))
Eventually(session).Should(Say(`cf map-route APP_NAME DOMAIN \[--port PORT]\n`))
Eventually(session).Should(Say(`\n`))

Eventually(session).Should(Say(`EXAMPLES:`))
Eventually(session).Should(Say(`cf map-route my-app example.com # example.com`))
Eventually(session).Should(Say(`cf map-route my-app example.com --hostname myhost # myhost.example.com`))
Eventually(session).Should(Say(`cf map-route my-app example.com --hostname myhost --path foo # myhost.example.com/foo`))
Eventually(session).Should(Say(`cf map-route my-app example.com --hostname myhost --app-protocol http2 # myhost.example.com`))
Eventually(session).Should(Say(`cf map-route my-app example.com --port 5000 # example.com:5000`))
Eventually(session).Should(Say(`cf map-route my-app example.com # example.com`))
Eventually(session).Should(Say(`cf map-route my-app example.com --hostname myhost # myhost.example.com`))
Eventually(session).Should(Say(`cf map-route my-app example.com --hostname myhost -o loadbalancing=least-connections # myhost.example.com with a per-route option`))
Eventually(session).Should(Say(`cf map-route my-app example.com --hostname myhost --path foo # myhost.example.com/foo`))
Eventually(session).Should(Say(`cf map-route my-app example.com --hostname myhost --app-protocol http2 # myhost.example.com`))
Eventually(session).Should(Say(`cf map-route my-app example.com --port 5000 # example.com:5000`))
Eventually(session).Should(Say(`\n`))

Eventually(session).Should(Say(`OPTIONS:`))
Eventually(session).Should(Say(`--hostname, -n\s+Hostname for the HTTP route \(required for shared domains\)`))
Eventually(session).Should(Say(`--path\s+Path for the HTTP route`))
Eventually(session).Should(Say(`--port\s+Port for the TCP route \(default: random port\)`))
Eventually(session).Should(Say(`--app-protocol\s+\[Beta flag, subject to change\] Protocol for the route destination \(default: http1\). Only applied to HTTP routes`))
Eventually(session).Should(Say(`--option, -o\s+Set the value of a per-route option`))

Eventually(session).Should(Say(`\n`))

Eventually(session).Should(Say(`SEE ALSO:`))
Eventually(session).Should(Say(`create-route, routes, unmap-route`))
Eventually(session).Should(Say(`create-route, routes, unmap-route, update-route`))

Eventually(session).Should(Exit(0))
})
2 changes: 1 addition & 1 deletion integration/v7/isolated/routes_command_test.go
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ import (
var _ = Describe("routes command", func() {

appProtocolValue := "http1"
const tableHeaders = `space\s+host\s+domain\s+port\s+path\s+protocol\s+app-protocol\s+apps\s+service instance`
const tableHeaders = `space\s+host\s+domain\s+port\s+path\s+protocol\s+app-protocol\s+apps\s+service instance\s+options`
Context("Help", func() {
It("appears in cf help -a", func() {
session := helpers.CF("help", "-a")
179 changes: 179 additions & 0 deletions integration/v7/isolated/update_route_command_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
package isolated

import (
. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
"code.cloudfoundry.org/cli/integration/helpers"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"
. "github.com/onsi/gomega/gexec"
)

var _ = Describe("update-route command", func() {
Context("Help", func() {
It("appears in cf help -a", func() {
session := helpers.CF("help", "-a")
Eventually(session).Should(Exit(0))
Expect(session).To(HaveCommandInCategoryWithDescription("update-route", "ROUTES", "Update a route by route specific options, e.g. load balancing algorithm"))
})

It("displays the help information", func() {
session := helpers.CF("update-route", "--help")
Eventually(session).Should(Say(`NAME:`))
Eventually(session).Should(Say(`update-route - Update a route by route specific options, e.g. load balancing algorithm\n`))
Eventually(session).Should(Say(`\n`))

Eventually(session).Should(Say(`USAGE:`))
Eventually(session).Should(Say(`Update an existing HTTP route:\n`))
Eventually(session).Should(Say(`cf update-route DOMAIN \[--hostname HOSTNAME\] \[--path PATH\] \[--option OPTION=VALUE\]\n`))
Eventually(session).Should(Say(`\n`))

Eventually(session).Should(Say(`EXAMPLES:`))
Eventually(session).Should(Say(`cf update-route example.com -o loadbalancing=round-robin`))
Eventually(session).Should(Say(`cf update-route example.com -o loadbalancing=least-connections`))
Eventually(session).Should(Say(`cf update-route example.com -r loadbalancing`))
Eventually(session).Should(Say(`cf update-route example.com --hostname myhost --path foo -o loadbalancing=round-robin`))
Eventually(session).Should(Say(`\n`))

Eventually(session).Should(Say(`OPTIONS:`))
Eventually(session).Should(Say(`--hostname, -n\s+Hostname for the HTTP route \(required for shared domains\)`))
Eventually(session).Should(Say(`--path\s+Path for the HTTP route`))
Eventually(session).Should(Say(`--port\s+Port for the TCP route \(default: random port\)`))
Eventually(session).Should(Say(`--option, -o\s+Set the value of a per-route option`))
Eventually(session).Should(Say(`\n`))

Eventually(session).Should(Say(`SEE ALSO:`))
Eventually(session).Should(Say(`check-route, domains, map-route, routes, unmap-route`))

Eventually(session).Should(Exit(0))
})
})

When("the environment is not setup correctly", func() {
It("fails with the appropriate errors", func() {
helpers.CheckEnvironmentTargetedCorrectly(true, false, ReadOnlyOrg, "update-route", "some-domain")
})
})

When("the environment is set up correctly", func() {
var (
orgName string
spaceName string
)

BeforeEach(func() {
orgName = helpers.NewOrgName()
spaceName = helpers.NewSpaceName()

helpers.SetupCF(orgName, spaceName)
})

AfterEach(func() {
helpers.QuickDeleteOrg(orgName)
})

When("the space and domain exist", func() {
var (
userName string
domainName string
)

BeforeEach(func() {
domainName = helpers.NewDomainName()
userName, _ = helpers.GetCredentials()
})

When("the route already exists", func() {
var (
domain helpers.Domain
hostname string
option string
path string
)

BeforeEach(func() {
domain = helpers.NewDomain(orgName, domainName)
hostname = "key-lime-pie"
path = "/a"
domain.CreatePrivate()
Eventually(helpers.CF("create-route", domainName, "--hostname", hostname, "--path", path)).Should(Exit(0))
})

AfterEach(func() {
domain.Delete()
})
When("a route option is specified", func() {
It("updates the route and runs to completion without failing", func() {
option = "loadbalancing=round-robin"
session := helpers.CF("update-route", domainName, "--hostname", hostname, "--option", option)
Eventually(session).Should(Say(`Updating route %s\.%s for org %s / space %s as %s\.\.\.`, hostname, domainName, orgName, spaceName, userName))
Eventually(session).Should(Say(`Route %s\.%s has been updated\.`, hostname, domainName))
Eventually(session).Should(Say(`OK`))
Eventually(session).Should(Exit(0))
})
})

When("route options are not specified", func() {
It("gives an error message and fails", func() {
session := helpers.CF("update-route", domainName, "--hostname", hostname)
Eventually(session).Should(Say(`No options were specified for the update of the Route %s`, domainName))
Eventually(session).Should(Exit(1))
})
})

When("route options are specified in the wrong format", func() {
It("gives an error message and fails", func() {
session := helpers.CF("update-route", domainName, "--hostname", hostname, "-- option", "loadbalancing")
Eventually(session).Should(Say(`Route option '%s' for route with host '%s', domain '%s', and path '%s' was specified incorrectly. Please use key-value pair format key=value.`, "loadbalancing", hostname, domainName, path))
Eventually(session).Should(Exit(1))
})
})
})

When("the route does not exist", func() {
var (
domain helpers.Domain
hostname string
option string
)

BeforeEach(func() {
domain = helpers.NewDomain(orgName, domainName)
hostname = "key-lime-pie"
option = "loadbalancing=round-robin"
domain.CreatePrivate()
})

AfterEach(func() {
domain.Delete()
})

It("gives an error message", func() {
session := helpers.CF("update-route", domainName, "--hostname", hostname, "--option", option)
Eventually(session).Should(Say(`Updating route %s\.%s for org %s / space %s as %s\.\.\.`, hostname, domainName, orgName, spaceName, userName))
Eventually(session.Err).Should(Say(`API endpoint not found at`))
Eventually(session).Should(Exit(0))
})
})

})

When("the domain does not exist", func() {
It("gives an error message and exits", func() {
session := helpers.CF("update-route", "some-domain")
Eventually(session.Err).Should(Say(`Domain %s not found.`, "some-domain"))
Eventually(session).Should(Exit(0))
})
})

When("the domain is not specified", func() {
It("displays error and exits 1", func() {
session := helpers.CF("update-route")
Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `DOMAIN` was not provided\n"))
Eventually(session.Err).Should(Say("\n"))
Eventually(session).Should(Say("NAME:\n"))
Eventually(session).Should(Exit(1))
})
})
})
})

0 comments on commit 3faf27d

Please sign in to comment.