Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle optional flags correctly in VRF route update #441

Merged
merged 4 commits into from
Jan 31, 2024
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
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
Loading