Skip to content

Commit

Permalink
Refactor test utils
Browse files Browse the repository at this point in the history
- Replace `Eventually` with `EventuallyWithOffset`
- Use native Gomega assertions instead of custom assertions

Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com>
  • Loading branch information
dhaiducek authored and openshift-merge-robot committed May 18, 2023
1 parent 7c79594 commit 3e915f5
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions test/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func GetClusterLevelWithTimeout(
}
var obj *unstructured.Unstructured

Eventually(func() error {
EventuallyWithOffset(1, func() error {
var err error
namespace := clientHubDynamic.Resource(gvr)
obj, err = namespace.Get(context.TODO(), name, metav1.GetOptions{})
Expand All @@ -74,7 +74,7 @@ func GetClusterLevelWithTimeout(
}

return nil
}, timeout, 1).Should(BeNil())
}, timeout, 1).ShouldNot(HaveOccurred())

if wantFound {
return obj
Expand All @@ -97,7 +97,7 @@ func GetWithTimeout(
}
var obj *unstructured.Unstructured

Eventually(func() error {
EventuallyWithOffset(1, func() error {
var err error
namespace := clientHubDynamic.Resource(gvr).Namespace(namespace)
obj, err = namespace.Get(context.TODO(), name, metav1.GetOptions{})
Expand All @@ -112,7 +112,7 @@ func GetWithTimeout(
}

return nil
}, timeout, 1).Should(BeNil())
}, timeout, 1).ShouldNot(HaveOccurred())

if wantFound {
return obj
Expand All @@ -136,17 +136,13 @@ func ListWithTimeout(
}
var list *unstructured.UnstructuredList

Eventually(func() error {
EventuallyWithOffset(1, func(g Gomega) []unstructured.Unstructured {
var err error
list, err = clientHubDynamic.Resource(gvr).List(context.TODO(), opts)
if err != nil {
return err
} else if len(list.Items) != size {
return fmt.Errorf("list size doesn't match, expected %d actual %d", size, len(list.Items))
}
g.Expect(err).ToNot(HaveOccurred())

return nil
}, timeout, 1).Should(BeNil())
return list.Items
}, timeout, 1).Should(HaveLen(size))

if wantFound {
return list
Expand All @@ -160,12 +156,12 @@ func GetMatchingEvents(
) []corev1.Event {
var eventList *corev1.EventList

Eventually(func() error {
EventuallyWithOffset(1, func() error {
var err error
eventList, err = client.CoreV1().Events(namespace).List(context.TODO(), metav1.ListOptions{})

return err
}, timeout, 1).Should(BeNil())
}, timeout, 1).ShouldNot(HaveOccurred())

matchingEvents := make([]corev1.Event, 0)
msgMatcher := regexp.MustCompile(msgRegex)
Expand Down Expand Up @@ -331,10 +327,9 @@ func DoConfigPolicyMessageTest(clientHubDynamic dynamic.Interface,
gvrConfigPolicy schema.GroupVersionResource, namespace string, policyName string,
templateIdx int, timeout int, expectedMsg string,
) {
Eventually(func(g Gomega) string {
EventuallyWithOffset(1, func(g Gomega) string {
message, _, err := getConfigPolicyStatusMessages(clientHubDynamic,
gvrConfigPolicy, namespace, policyName, templateIdx)

g.Expect(err).ShouldNot(HaveOccurred())

return message
Expand Down

0 comments on commit 3e915f5

Please sign in to comment.