Skip to content

Commit aaea4d8

Browse files
Main fix routes (#3431) (#3432)
1 parent 4316b68 commit aaea4d8

File tree

6 files changed

+54
-40
lines changed

6 files changed

+54
-40
lines changed

command/v7/create_route_command.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,17 @@ func (cmd CreateRouteCommand) Execute(args []string) error {
6969
"Organization": orgName,
7070
})
7171

72-
err = cmd.validateAPIVersionForPerRouteOptions()
73-
if err != nil {
74-
return err
75-
}
76-
77-
routeOptions, wrongOptSpec := resources.CreateRouteOptions(cmd.Options)
78-
if wrongOptSpec != nil {
79-
return actionerror.RouteOptionError{
80-
Name: *wrongOptSpec,
81-
DomainName: domain,
82-
Path: pathName,
83-
Host: hostname,
72+
var routeOptions map[string]*string
73+
if len(cmd.Options) > 0 && cmd.validateAPIVersionForPerRouteOptions() == nil {
74+
var wrongOptSpec *string
75+
routeOptions, wrongOptSpec = resources.CreateRouteOptions(cmd.Options)
76+
if wrongOptSpec != nil {
77+
return actionerror.RouteOptionError{
78+
Name: *wrongOptSpec,
79+
DomainName: domain,
80+
Path: pathName,
81+
Host: hostname,
82+
}
8483
}
8584
}
8685
route, warnings, err := cmd.Actor.CreateRoute(spaceGUID, domain, hostname, pathName, port, routeOptions)

command/v7/create_route_command_test.go

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,15 @@ var _ = Describe("create-route Command", func() {
164164
})
165165
})
166166

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

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

208-
It("creates the route", func() {
209-
Expect(fakeActor.CreateRouteCallCount()).To(Equal(1))
210-
expectedSpaceGUID, expectedDomainName, expectedHostname, _, _, expectedOptions := fakeActor.CreateRouteArgsForCall(0)
211-
Expect(expectedSpaceGUID).To(Equal(spaceGUID))
212-
Expect(expectedDomainName).To(Equal(domainName))
213-
Expect(expectedHostname).To(Equal(hostname))
214-
Expect(expectedOptions).To(Equal(options))
208+
When("in a version of CAPI that does not support options", func() {
209+
BeforeEach(func() {
210+
fakeActor.CreateRouteReturns(resources.Route{
211+
URL: domainName,
212+
}, v7action.Warnings{"warnings-1", "warnings-2"}, nil)
213+
cmdOptions = []string{}
214+
cCAPIOldVersion = strconv.Itoa(1)
215+
fakeConfig.APIVersionReturns(cCAPIOldVersion)
216+
})
217+
218+
It("creates the route when no options are provided", func() {
219+
Expect(fakeActor.CreateRouteCallCount()).To(Equal(1))
220+
expectedSpaceGUID, expectedDomainName, expectedHostname, _, _, expectedOptions := fakeActor.CreateRouteArgsForCall(0)
221+
Expect(expectedSpaceGUID).To(Equal(spaceGUID))
222+
Expect(expectedDomainName).To(Equal(domainName))
223+
Expect(expectedHostname).To(Equal(hostname))
224+
Expect(expectedOptions).To(BeNil())
225+
})
215226
})
216227

217228
When("passing in a hostname", func() {

command/v7/map_route_command.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,21 @@ func (cmd MapRouteCommand) Execute(args []string) error {
7272
if _, ok := err.(actionerror.RouteNotFoundError); !ok {
7373
return err
7474
}
75-
if cmd.Options != nil && len(cmd.Options) > 0 {
76-
err := cmd.validateAPIVersionForPerRouteOptions()
77-
if err != nil {
78-
return err
79-
}
80-
}
81-
routeOptions, wrongOptSpec := resources.CreateRouteOptions(cmd.Options)
82-
if wrongOptSpec != nil {
83-
return actionerror.RouteOptionError{
84-
Name: *wrongOptSpec,
85-
DomainName: domain.Name,
86-
Path: path,
87-
Host: cmd.Hostname,
75+
76+
var routeOptions map[string]*string
77+
if len(cmd.Options) > 0 && cmd.validateAPIVersionForPerRouteOptions() == nil {
78+
var wrongOptSpec *string
79+
routeOptions, wrongOptSpec = resources.CreateRouteOptions(cmd.Options)
80+
if wrongOptSpec != nil {
81+
return actionerror.RouteOptionError{
82+
Name: *wrongOptSpec,
83+
DomainName: domain.Name,
84+
Path: path,
85+
Host: cmd.Hostname,
86+
}
8887
}
8988
}
89+
9090
cmd.UI.DisplayTextWithFlavor("Creating route {{.URL}} for org {{.OrgName}} / space {{.SpaceName}} as {{.User}}...",
9191
map[string]interface{}{
9292
"URL": url,
@@ -109,7 +109,7 @@ func (cmd MapRouteCommand) Execute(args []string) error {
109109
}
110110
cmd.UI.DisplayOK()
111111
} else {
112-
if cmd.Options != nil && len(cmd.Options) > 0 {
112+
if len(cmd.Options) > 0 {
113113
return actionerror.RouteOptionSupportError{ErrorText: "Route specific options can only be specified for nonexistent routes."}
114114
}
115115
}

command/v7/map_route_command_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ var _ = Describe("map-route Command", func() {
310310
Expect(testUI.Err).To(Say("get-app-warnings"))
311311
Expect(testUI.Err).To(Say("CC API version"))
312312
Expect(testUI.Err).To(Say("does not support per-route options"))
313-
Expect(executeErr).To(HaveOccurred())
314-
Expect(fakeActor.CreateRouteCallCount()).To(Equal(0))
313+
Expect(executeErr).NotTo(HaveOccurred())
314+
Expect(fakeActor.CreateRouteCallCount()).To(Equal(1))
315315
})
316316
})
317317

command/v7/update_route_command.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ func (cmd UpdateRouteCommand) Execute(args []string) error {
6262
return err
6363
}
6464
}
65+
66+
// Update route only works for per route options. The command will fail instead instead of just
67+
// ignoring the per-route options like it is the case for create-route and map-route.
6568
err = cmd.validateAPIVersionForPerRouteOptions()
6669
if err != nil {
6770
return err
@@ -72,7 +75,7 @@ func (cmd UpdateRouteCommand) Execute(args []string) error {
7275
ErrorText: fmt.Sprintf("No options were specified for the update of the Route %s", route.URL)}
7376
}
7477

75-
if cmd.Options != nil {
78+
if len(cmd.Options) > 0 {
7679
routeOpts, wrongOptSpec := resources.CreateRouteOptions(cmd.Options)
7780
if wrongOptSpec != nil {
7881
return actionerror.RouteOptionError{

command/v7/update_route_command_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ var _ = Describe("update-route Command", func() {
269269
})
270270
})
271271
})
272+
272273
When("getting the route errors", func() {
273274
BeforeEach(func() {
274275
fakeActor.GetRouteByAttributesReturns(

0 commit comments

Comments
 (0)