Skip to content

Commit

Permalink
Wait until devices appear
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaspence committed Mar 3, 2023
1 parent c0a5d5b commit 1363df2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
5 changes: 0 additions & 5 deletions internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ func runTests(m *testing.M) int {
panic(err)
}

w := wait.ForHTTP("/status").WithPort(port).WithTLS(true).WithAllowInsecure(true)
if err = w.WaitUntilReady(ctx, container); err != nil {
panic(err)
}

testClient = &unifi.Client{}
setHTTPClient(testClient, true, "unifi")
testClient.SetBaseURL(endpoint)
Expand Down
39 changes: 25 additions & 14 deletions internal/provider/resource_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,36 @@ func allocateDevice(t *testing.T) (string, func()) {
ctx := context.Background()

deviceInit.Do(func() {
devices, err := testClient.ListDevice(ctx, "default")
if err != nil {
t.Fatalf("Error listing devices: %s", err)
}

for _, device := range devices {
if device.Type != "usw" {
continue
// The demo devices don't appear instantly when the controller starts.
err := resource.RetryContext(ctx, 1*time.Minute, func() *resource.RetryError {
devices, err := testClient.ListDevice(ctx, "default")
if err != nil {
return resource.NonRetryableError(fmt.Errorf("Error listing devices: %w", err))
}

// These devices aren't really switches.
if device.Model == "USPRPS" || device.Model == "USPRPSP" || device.Model == "USPPDUHD" || device.Model == "USPPDUP" {
continue
if len(devices) == 0 {
return resource.RetryableError(fmt.Errorf("No devices found"))
}

d := device
if ok := devicePool.Add(&d); !ok {
t.Fatal("Failed to add device to pool")
for _, device := range devices {
if device.Type != "usw" {
continue
}

// These devices aren't really switches.
if device.Model == "USPRPS" || device.Model == "USPRPSP" || device.Model == "USPPDUHD" || device.Model == "USPPDUP" {
continue
}

d := device
if ok := devicePool.Add(&d); !ok {
return resource.NonRetryableError("Failed to add device to pool")
}
}
})

if err != nil {
t.Fatal(err)
}
})

Expand Down

0 comments on commit 1363df2

Please sign in to comment.