Skip to content

Commit f75c2de

Browse files
Main fix routes (#3431)
* Fixed the create route command, missing update-route Signed-off-by: João Pereira <joao.pereira@broadcom.com> * fix: don't fail if CC does not support per-route options --------- Signed-off-by: João Pereira <joao.pereira@broadcom.com> Co-authored-by: João Pereira <joao.pereira@broadcom.com>
1 parent a8ccec6 commit f75c2de

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
@@ -68,18 +68,17 @@ func (cmd CreateRouteCommand) Execute(args []string) error {
6868
"Organization": orgName,
6969
})
7070

71-
err = cmd.validateAPIVersionForPerRouteOptions()
72-
if err != nil {
73-
return err
74-
}
75-
76-
routeOptions, wrongOptSpec := resources.CreateRouteOptions(cmd.Options)
77-
if wrongOptSpec != nil {
78-
return actionerror.RouteOptionError{
79-
Name: *wrongOptSpec,
80-
DomainName: domain,
81-
Path: pathName,
82-
Host: hostname,
71+
var routeOptions map[string]*string
72+
if len(cmd.Options) > 0 && cmd.validateAPIVersionForPerRouteOptions() == nil {
73+
var wrongOptSpec *string
74+
routeOptions, wrongOptSpec = resources.CreateRouteOptions(cmd.Options)
75+
if wrongOptSpec != nil {
76+
return actionerror.RouteOptionError{
77+
Name: *wrongOptSpec,
78+
DomainName: domain,
79+
Path: pathName,
80+
Host: hostname,
81+
}
8382
}
8483
}
8584
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
@@ -268,6 +268,7 @@ var _ = Describe("update-route Command", func() {
268268
})
269269
})
270270
})
271+
271272
When("getting the route errors", func() {
272273
BeforeEach(func() {
273274
fakeActor.GetRouteByAttributesReturns(

0 commit comments

Comments
 (0)