Skip to content

Commit b5d15ca

Browse files
committed
test: Add helper function to wait for misc. resources to be present
1 parent 805b228 commit b5d15ca

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

test/e2e/resource_helpers.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//go:build e2e
2+
3+
// Copyright 2024 Nutanix. All rights reserved.
4+
// SPDX-License-Identifier: Apache-2.0
5+
6+
package e2e
7+
8+
import (
9+
"context"
10+
"fmt"
11+
"time"
12+
13+
. "github.com/onsi/gomega"
14+
capie2e "sigs.k8s.io/cluster-api/test/e2e"
15+
"sigs.k8s.io/cluster-api/test/framework"
16+
"sigs.k8s.io/controller-runtime/pkg/client"
17+
)
18+
19+
// WaitForResourcesInput is the input for WaitForResources.
20+
type WaitForResourcesInput struct {
21+
Getter framework.Getter
22+
Resources []client.Object
23+
}
24+
25+
// WaitForResources waits until the resources are present.
26+
func WaitForResources(
27+
ctx context.Context,
28+
input WaitForResourcesInput,
29+
intervals ...interface{},
30+
) {
31+
start := time.Now()
32+
33+
for i := range input.Resources {
34+
obj := input.Resources[i].DeepCopyObject().(client.Object)
35+
key := client.ObjectKeyFromObject(obj)
36+
capie2e.Byf("waiting for resource %s %s to be present",
37+
obj.GetObjectKind().GroupVersionKind(),
38+
key,
39+
)
40+
Logf("starting to wait for resource %s %s to become present",
41+
obj.GetObjectKind().GroupVersionKind(),
42+
key,
43+
)
44+
Eventually(func() bool {
45+
if err := input.Getter.Get(ctx, key, obj); err != nil {
46+
return false
47+
}
48+
return true
49+
}, intervals...).Should(BeTrue(),
50+
fmt.Sprintf("Resource %s %s was not found",
51+
obj.GetObjectKind().GroupVersionKind(),
52+
key,
53+
),
54+
)
55+
Logf("Resource %s is now available, took %v",
56+
obj.GetObjectKind().GroupVersionKind(),
57+
key,
58+
time.Since(start),
59+
)
60+
}
61+
}

0 commit comments

Comments
 (0)