Skip to content

Commit 10d7143

Browse files
authored
fix: handle optional flags correctly in VRF route update (#441)
The test for the VRF route update subcommand was explicitly skipped. I added a helper function to wait for the VRF route to be ready before testing the update subcommand, but when the test was enabled it failed because the subcommand was not capable of updating tags without updating all other VRF route properties. In addition to enabling the test for the VRF route update subcommand, this updates the subcommand itself so that it only updates a VRF route property if the user set the corresponding CLI flag. Part of #414
2 parents 60d0035 + 49b4826 commit 10d7143

3 files changed

Lines changed: 25 additions & 19 deletions

File tree

.github/workflows/e2e-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ jobs:
4848
- name: Get dependencies
4949
run: go mod download
5050
- name: Run end-to-end tests
51-
run: go test -v -cover -coverpkg=./... -parallel 4 ./test/e2e/... -timeout 1000s
51+
run: go test -v -cover -coverpkg=./... -parallel 4 ./test/e2e/... -timeout 180m
5252
env:
5353
METAL_AUTH_TOKEN: ${{ secrets.METAL_AUTH_TOKEN }}

internal/vrf/updateroute.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,16 @@ func (c *Client) UpdateRoute() *cobra.Command {
2929
inc := []string{}
3030
exc := []string{}
3131

32-
vrfRouteUpdateInput := metalv1.VrfRouteUpdateInput{
33-
Prefix: &prefix,
34-
NextHop: &nextHop,
35-
Tags: tags,
32+
vrfRouteUpdateInput := metalv1.VrfRouteUpdateInput{}
33+
34+
if prefix != "" {
35+
vrfRouteUpdateInput.Prefix = &prefix
36+
}
37+
if nextHop != "" {
38+
vrfRouteUpdateInput.NextHop = &nextHop
39+
}
40+
if cmd.Flag("tags").Changed {
41+
vrfRouteUpdateInput.Tags = tags
3642
}
3743

3844
vrfRoute, _, err := c.Service.UpdateVrfRouteById(context.Background(), vrfID).VrfRouteUpdateInput(vrfRouteUpdateInput).Include(c.Servicer.Includes(inc)).Exclude(c.Servicer.Excludes(exc)).Execute()

test/e2e/vrfstest/vrf_route_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"regexp"
55
"strings"
66
"testing"
7+
"time"
78

89
root "github.com/equinix/metal-cli/internal/cli"
910
outputPkg "github.com/equinix/metal-cli/internal/outputs"
@@ -113,10 +114,6 @@ func TestCli_Vrf_Route(t *testing.T) {
113114
},
114115
want: &cobra.Command{},
115116
cmdFunc: func(t *testing.T, c *cobra.Command) {
116-
// Actually user have to wait for 5 min to updae the VRF-routes. This test case is skipped intentionally
117-
if true {
118-
t.Skip("Skipping this test because someCondition is true")
119-
}
120117
root := c.Root()
121118

122119
projName := "metal-cli-" + randName + "-vrf-list-test"
@@ -128,19 +125,22 @@ func TestCli_Vrf_Route(t *testing.T) {
128125

129126
ipReservation := helper.CreateTestVrfIpRequest(t, projectId.GetId(), vrf.GetId())
130127
_ = helper.CreateTestVrfGateway(t, projectId.GetId(), ipReservation.VrfIpReservation.GetId(), vlan.GetId())
131-
_ = helper.CreateTestVrfRoute(t, vrf.GetId())
128+
route := helper.CreateTestVrfRoute(t, vrf.GetId())
132129

133-
if vlan.GetId() != "" && vrf.GetId() != "" {
134-
root.SetArgs([]string{subCommand, "update-route", "-i", vrf.GetId(), "-t", "foobar"})
130+
// We literally need to sleep for 5 minutes; the API will reject any
131+
// VRF route update request that comes in less than 5 minutes after
132+
// the VRF route was last updated
133+
time.Sleep(300 * time.Second)
135134

136-
out := helper.ExecuteAndCaptureOutput(t, root)
135+
root.SetArgs([]string{subCommand, "update-route", "-i", route.GetId(), "-t", "foobar"})
137136

138-
if !strings.Contains(string(out[:]), "TYPE") &&
139-
!strings.Contains(string(out[:]), "static") &&
140-
!strings.Contains(string(out[:]), "PREFIX") &&
141-
!strings.Contains(string(out[:]), "0.0.0.0/0") {
142-
t.Error("expected output should include TYPE static PREFIX and 0.0.0.0/0, in the out string ")
143-
}
137+
out := helper.ExecuteAndCaptureOutput(t, root)
138+
139+
if !strings.Contains(string(out[:]), "TYPE") &&
140+
!strings.Contains(string(out[:]), "static") &&
141+
!strings.Contains(string(out[:]), "PREFIX") &&
142+
!strings.Contains(string(out[:]), "0.0.0.0/0") {
143+
t.Error("expected output should include TYPE static PREFIX and 0.0.0.0/0, in the out string ")
144144
}
145145
}
146146
},

0 commit comments

Comments
 (0)