Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions command/v7/create_route_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,17 @@ func (cmd CreateRouteCommand) Execute(args []string) error {
"Organization": orgName,
})

err = cmd.validateAPIVersionForPerRouteOptions()
if err != nil {
return err
}

routeOptions, wrongOptSpec := resources.CreateRouteOptions(cmd.Options)
if wrongOptSpec != nil {
return actionerror.RouteOptionError{
Name: *wrongOptSpec,
DomainName: domain,
Path: pathName,
Host: hostname,
var routeOptions map[string]*string
if len(cmd.Options) > 0 && cmd.validateAPIVersionForPerRouteOptions() == nil {
var wrongOptSpec *string
routeOptions, wrongOptSpec = resources.CreateRouteOptions(cmd.Options)
if wrongOptSpec != nil {
return actionerror.RouteOptionError{
Name: *wrongOptSpec,
DomainName: domain,
Path: pathName,
Host: hostname,
}
}
}
route, warnings, err := cmd.Actor.CreateRoute(spaceGUID, domain, hostname, pathName, port, routeOptions)
Expand Down
33 changes: 22 additions & 11 deletions command/v7/create_route_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ var _ = Describe("create-route Command", func() {
})
})

When("creating the route fails when the CC API version is too old for route options", func() {
When("creating the route does not fail when the CC API version is too old for route options", func() {
BeforeEach(func() {
cCAPIOldVersion = strconv.Itoa(1)
fakeConfig.APIVersionReturns(cCAPIOldVersion)
})

It("does not create a route and gives error message", func() {
Expect(executeErr).To(HaveOccurred())
Expect(fakeActor.CreateRouteCallCount()).To(Equal(0))
It("does create a route and gives a warning message", func() {
Expect(executeErr).NotTo(HaveOccurred())
Expect(fakeActor.CreateRouteCallCount()).To(Equal(1))
Expect(testUI.Err).To(Say("Your CC API"))
Expect(testUI.Err).To(Say("does not support per-route options"))
})
Expand Down Expand Up @@ -205,13 +205,24 @@ var _ = Describe("create-route Command", func() {
Expect(testUI.Out).To(Say("OK"))
})

It("creates the route", func() {
Expect(fakeActor.CreateRouteCallCount()).To(Equal(1))
expectedSpaceGUID, expectedDomainName, expectedHostname, _, _, expectedOptions := fakeActor.CreateRouteArgsForCall(0)
Expect(expectedSpaceGUID).To(Equal(spaceGUID))
Expect(expectedDomainName).To(Equal(domainName))
Expect(expectedHostname).To(Equal(hostname))
Expect(expectedOptions).To(Equal(options))
When("in a version of CAPI that does not support options", func() {
BeforeEach(func() {
fakeActor.CreateRouteReturns(resources.Route{
URL: domainName,
}, v7action.Warnings{"warnings-1", "warnings-2"}, nil)
cmdOptions = []string{}
cCAPIOldVersion = strconv.Itoa(1)
fakeConfig.APIVersionReturns(cCAPIOldVersion)
})

It("creates the route when no options are provided", func() {
Expect(fakeActor.CreateRouteCallCount()).To(Equal(1))
expectedSpaceGUID, expectedDomainName, expectedHostname, _, _, expectedOptions := fakeActor.CreateRouteArgsForCall(0)
Expect(expectedSpaceGUID).To(Equal(spaceGUID))
Expect(expectedDomainName).To(Equal(domainName))
Expect(expectedHostname).To(Equal(hostname))
Expect(expectedOptions).To(BeNil())
})
})

When("passing in a hostname", func() {
Expand Down
28 changes: 14 additions & 14 deletions command/v7/map_route_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,21 @@ func (cmd MapRouteCommand) Execute(args []string) error {
if _, ok := err.(actionerror.RouteNotFoundError); !ok {
return err
}
if cmd.Options != nil && len(cmd.Options) > 0 {
err := cmd.validateAPIVersionForPerRouteOptions()
if err != nil {
return err
}
}
routeOptions, wrongOptSpec := resources.CreateRouteOptions(cmd.Options)
if wrongOptSpec != nil {
return actionerror.RouteOptionError{
Name: *wrongOptSpec,
DomainName: domain.Name,
Path: path,
Host: cmd.Hostname,

var routeOptions map[string]*string
if len(cmd.Options) > 0 && cmd.validateAPIVersionForPerRouteOptions() == nil {
var wrongOptSpec *string
routeOptions, wrongOptSpec = resources.CreateRouteOptions(cmd.Options)
if wrongOptSpec != nil {
return actionerror.RouteOptionError{
Name: *wrongOptSpec,
DomainName: domain.Name,
Path: path,
Host: cmd.Hostname,
}
}
}

cmd.UI.DisplayTextWithFlavor("Creating route {{.URL}} for org {{.OrgName}} / space {{.SpaceName}} as {{.User}}...",
map[string]interface{}{
"URL": url,
Expand All @@ -109,7 +109,7 @@ func (cmd MapRouteCommand) Execute(args []string) error {
}
cmd.UI.DisplayOK()
} else {
if cmd.Options != nil && len(cmd.Options) > 0 {
if len(cmd.Options) > 0 {
return actionerror.RouteOptionSupportError{ErrorText: "Route specific options can only be specified for nonexistent routes."}
}
}
Expand Down
4 changes: 2 additions & 2 deletions command/v7/map_route_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ var _ = Describe("map-route Command", func() {
Expect(testUI.Err).To(Say("get-app-warnings"))
Expect(testUI.Err).To(Say("CC API version"))
Expect(testUI.Err).To(Say("does not support per-route options"))
Expect(executeErr).To(HaveOccurred())
Expect(fakeActor.CreateRouteCallCount()).To(Equal(0))
Expect(executeErr).NotTo(HaveOccurred())
Expect(fakeActor.CreateRouteCallCount()).To(Equal(1))
})
})

Expand Down
5 changes: 4 additions & 1 deletion command/v7/update_route_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func (cmd UpdateRouteCommand) Execute(args []string) error {
return err
}
}

// Update route only works for per route options. The command will fail instead instead of just
// ignoring the per-route options like it is the case for create-route and map-route.
err = cmd.validateAPIVersionForPerRouteOptions()
if err != nil {
return err
Expand All @@ -72,7 +75,7 @@ func (cmd UpdateRouteCommand) Execute(args []string) error {
ErrorText: fmt.Sprintf("No options were specified for the update of the Route %s", route.URL)}
}

if cmd.Options != nil {
if len(cmd.Options) > 0 {
routeOpts, wrongOptSpec := resources.CreateRouteOptions(cmd.Options)
if wrongOptSpec != nil {
return actionerror.RouteOptionError{
Expand Down
1 change: 1 addition & 0 deletions command/v7/update_route_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ var _ = Describe("update-route Command", func() {
})
})
})

When("getting the route errors", func() {
BeforeEach(func() {
fakeActor.GetRouteByAttributesReturns(
Expand Down
Loading