From 3faf27d5a9ad6cf0fdd301a77b2d434a7e3cb3b3 Mon Sep 17 00:00:00 2001 From: D067386 Date: Thu, 30 Jan 2025 10:49:06 +0100 Subject: [PATCH] New integration test and adjustments of other tests --- command/v7/update_route_command.go | 9 +- command/v7/update_route_command_test.go | 5 +- .../v7/isolated/create_route_command_test.go | 8 +- .../v7/isolated/map_route_command_test.go | 16 +- .../v7/isolated/routes_command_test.go | 2 +- .../v7/isolated/update_route_command_test.go | 179 ++++++++++++++++++ 6 files changed, 201 insertions(+), 18 deletions(-) create mode 100644 integration/v7/isolated/update_route_command_test.go diff --git a/command/v7/update_route_command.go b/command/v7/update_route_command.go index bd0378b0043..6bf83430b5b 100644 --- a/command/v7/update_route_command.go +++ b/command/v7/update_route_command.go @@ -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 { diff --git a/command/v7/update_route_command_test.go b/command/v7/update_route_command_test.go index 5e192f24b05..399119c98da 100644 --- a/command/v7/update_route_command_test.go +++ b/command/v7/update_route_command_test.go @@ -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")) }) }) diff --git a/integration/v7/isolated/create_route_command_test.go b/integration/v7/isolated/create_route_command_test.go index 60e64ba82a6..8d71db79733 100644 --- a/integration/v7/isolated/create_route_command_test.go +++ b/integration/v7/isolated/create_route_command_test.go @@ -27,9 +27,9 @@ 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:`)) @@ -37,16 +37,18 @@ var _ = Describe("create-route command", func() { 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)) }) diff --git a/integration/v7/isolated/map_route_command_test.go b/integration/v7/isolated/map_route_command_test.go index 3f84f267b42..b81fca013d0 100644 --- a/integration/v7/isolated/map_route_command_test.go +++ b/integration/v7/isolated/map_route_command_test.go @@ -29,17 +29,18 @@ 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:`)) @@ -47,11 +48,12 @@ var _ = Describe("map-route command", func() { 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)) }) diff --git a/integration/v7/isolated/routes_command_test.go b/integration/v7/isolated/routes_command_test.go index 4f5ff25fcd4..8109f7422df 100644 --- a/integration/v7/isolated/routes_command_test.go +++ b/integration/v7/isolated/routes_command_test.go @@ -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") diff --git a/integration/v7/isolated/update_route_command_test.go b/integration/v7/isolated/update_route_command_test.go new file mode 100644 index 00000000000..53a72d733a7 --- /dev/null +++ b/integration/v7/isolated/update_route_command_test.go @@ -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)) + }) + }) + }) +})