Skip to content

Commit a1968b4

Browse files
committed
hard-code a 5-minute wait because that's what the API does
1 parent b7a87d5 commit a1968b4

File tree

2 files changed

+6
-30
lines changed

2 files changed

+6
-30
lines changed

test/e2e/vrfstest/vrf_route_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"regexp"
55
"strings"
66
"testing"
7+
"time"
78

8-
"github.com/equinix/equinix-sdk-go/services/metalv1"
99
root "github.com/equinix/metal-cli/internal/cli"
1010
outputPkg "github.com/equinix/metal-cli/internal/outputs"
1111
"github.com/equinix/metal-cli/internal/vrf"
@@ -127,7 +127,10 @@ func TestCli_Vrf_Route(t *testing.T) {
127127
_ = helper.CreateTestVrfGateway(t, projectId.GetId(), ipReservation.VrfIpReservation.GetId(), vlan.GetId())
128128
route := helper.CreateTestVrfRoute(t, vrf.GetId())
129129

130-
_ = helper.WaitForVrfRouteState(t, route.GetId(), metalv1.VRFROUTESTATUS_ACTIVE)
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)
131134

132135
root.SetArgs([]string{subCommand, "update-route", "-i", route.GetId(), "-t", "foobar"})
133136

test/helper/helper.go

+1-28
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestClient() *metalv1.APIClient {
2828
configuration.AddDefaultHeader("X-Auth-Token", os.Getenv("METAL_AUTH_TOKEN"))
2929
configuration.UserAgent = fmt.Sprintf("metal-cli/test-helper %s", configuration.UserAgent)
3030
// For debug purpose
31-
// configuration.Debug = true
31+
configuration.Debug = true
3232
apiClient := metalv1.NewAPIClient(configuration)
3333
return apiClient
3434
}
@@ -188,33 +188,6 @@ func WaitForDeviceState(t *testing.T, deviceId string, states ...metalv1.DeviceS
188188
return false, fmt.Errorf("timed out waiting for device %v state %v to become one of %v", deviceId, device.GetState(), states)
189189
}
190190

191-
func WaitForVrfRouteState(t *testing.T, routeId string, statuses ...metalv1.VrfRouteStatus) bool {
192-
var route *metalv1.VrfRoute
193-
var err error
194-
t.Helper()
195-
predefinedTime := 900 * time.Second // Adjust this as needed
196-
retryInterval := 10 * time.Second // Adjust this as needed
197-
startTime := time.Now()
198-
client := TestClient()
199-
for time.Since(startTime) < predefinedTime {
200-
route, _, err = client.VRFsApi.FindVrfRouteById(context.Background(), routeId).Execute()
201-
if err != nil {
202-
t.Fatal(err)
203-
return false
204-
}
205-
for _, status := range statuses {
206-
if route.GetStatus() == status {
207-
return true
208-
}
209-
}
210-
211-
// Sleep for the specified interval
212-
time.Sleep(retryInterval)
213-
}
214-
t.Fatalf("timed out waiting for VRF route %v status %v to become one of %v", routeId, route.GetStatus(), statuses)
215-
return false
216-
}
217-
218191
func WaitForAttachVlanToPort(t *testing.T, portId string, attach bool) error {
219192
t.Helper()
220193
ticker := time.NewTicker(5 * time.Second)

0 commit comments

Comments
 (0)