Skip to content

Commit

Permalink
fix: handle optional flags correctly in VRF route update (#441)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cprivitere authored Jan 31, 2024
2 parents 60d0035 + 49b4826 commit 10d7143
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ jobs:
- name: Get dependencies
run: go mod download
- name: Run end-to-end tests
run: go test -v -cover -coverpkg=./... -parallel 4 ./test/e2e/... -timeout 1000s
run: go test -v -cover -coverpkg=./... -parallel 4 ./test/e2e/... -timeout 180m
env:
METAL_AUTH_TOKEN: ${{ secrets.METAL_AUTH_TOKEN }}
14 changes: 10 additions & 4 deletions internal/vrf/updateroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ func (c *Client) UpdateRoute() *cobra.Command {
inc := []string{}
exc := []string{}

vrfRouteUpdateInput := metalv1.VrfRouteUpdateInput{
Prefix: &prefix,
NextHop: &nextHop,
Tags: tags,
vrfRouteUpdateInput := metalv1.VrfRouteUpdateInput{}

if prefix != "" {
vrfRouteUpdateInput.Prefix = &prefix
}
if nextHop != "" {
vrfRouteUpdateInput.NextHop = &nextHop
}
if cmd.Flag("tags").Changed {
vrfRouteUpdateInput.Tags = tags
}

vrfRoute, _, err := c.Service.UpdateVrfRouteById(context.Background(), vrfID).VrfRouteUpdateInput(vrfRouteUpdateInput).Include(c.Servicer.Includes(inc)).Exclude(c.Servicer.Excludes(exc)).Execute()
Expand Down
28 changes: 14 additions & 14 deletions test/e2e/vrfstest/vrf_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"regexp"
"strings"
"testing"
"time"

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

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

ipReservation := helper.CreateTestVrfIpRequest(t, projectId.GetId(), vrf.GetId())
_ = helper.CreateTestVrfGateway(t, projectId.GetId(), ipReservation.VrfIpReservation.GetId(), vlan.GetId())
_ = helper.CreateTestVrfRoute(t, vrf.GetId())
route := helper.CreateTestVrfRoute(t, vrf.GetId())

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

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

if !strings.Contains(string(out[:]), "TYPE") &&
!strings.Contains(string(out[:]), "static") &&
!strings.Contains(string(out[:]), "PREFIX") &&
!strings.Contains(string(out[:]), "0.0.0.0/0") {
t.Error("expected output should include TYPE static PREFIX and 0.0.0.0/0, in the out string ")
}
out := helper.ExecuteAndCaptureOutput(t, root)

if !strings.Contains(string(out[:]), "TYPE") &&
!strings.Contains(string(out[:]), "static") &&
!strings.Contains(string(out[:]), "PREFIX") &&
!strings.Contains(string(out[:]), "0.0.0.0/0") {
t.Error("expected output should include TYPE static PREFIX and 0.0.0.0/0, in the out string ")
}
}
},
Expand Down

0 comments on commit 10d7143

Please sign in to comment.