Skip to content

Commit c53bf03

Browse files
dhaiducekopenshift-merge-bot[bot]
authored andcommitted
Replace WithOffset() with GinkgoHelper()
Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com>
1 parent 474fdc8 commit c53bf03

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

test/e2e/case20_compliance_api_controller_test.go

+13-7
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ var _ = Describe("Test governance-policy-database secret changes and DB annotati
3737
nsName := fmt.Sprintf("case20-%d", seededRand.Int31())
3838

3939
createCase20Policy := func(ctx context.Context) {
40+
GinkgoHelper()
41+
4042
By("Creating " + case20PolicyName)
4143
utils.Kubectl("apply", "-f", case20PolicyYAML, "-n", nsName, "--kubeconfig="+kubeconfigHub)
4244
plc := utils.GetWithTimeout(
4345
clientHubDynamic, gvrPolicy, case20PolicyName, nsName, true, defaultTimeoutSeconds,
4446
)
45-
ExpectWithOffset(1, plc).NotTo(BeNil())
47+
Expect(plc).NotTo(BeNil())
4648

4749
By("Patching the placement with decision of cluster local-cluster")
4850
pld := utils.GetWithTimeout(
@@ -57,13 +59,13 @@ var _ = Describe("Test governance-policy-database secret changes and DB annotati
5759
_, err := clientHubDynamic.Resource(gvrPlacementDecision).Namespace(nsName).UpdateStatus(
5860
ctx, pld, metav1.UpdateOptions{},
5961
)
60-
ExpectWithOffset(1, err).ToNot(HaveOccurred())
62+
Expect(err).ToNot(HaveOccurred())
6163

6264
By("Waiting for the replicated policy")
6365
replicatedPolicy := utils.GetWithTimeout(
6466
clientHubDynamic, gvrPolicy, case20PolicyName, nsName, true, defaultTimeoutSeconds,
6567
)
66-
ExpectWithOffset(1, replicatedPolicy).NotTo(BeNil())
68+
Expect(replicatedPolicy).NotTo(BeNil())
6769
}
6870

6971
BeforeAll(func(ctx context.Context) {
@@ -144,8 +146,10 @@ var _ = Describe("Test governance-policy-database secret changes and DB annotati
144146
})
145147

146148
func bringDownDBConnection(ctx context.Context) {
149+
GinkgoHelper()
150+
147151
By("Setting the port to 12345")
148-
EventuallyWithOffset(1, func(g Gomega) {
152+
Eventually(func(g Gomega) {
149153
namespacedSecret := clientHub.CoreV1().Secrets("open-cluster-management")
150154
secret, err := namespacedSecret.Get(
151155
ctx, complianceeventsapi.DBSecretName, metav1.GetOptions{},
@@ -159,7 +163,7 @@ func bringDownDBConnection(ctx context.Context) {
159163
}, defaultTimeoutSeconds, 1).Should(Succeed())
160164

161165
By("Waiting for the database connection to be down")
162-
EventuallyWithOffset(1, func(g Gomega) {
166+
Eventually(func(g Gomega) {
163167
req, err := http.NewRequestWithContext(
164168
ctx, http.MethodGet, fmt.Sprintf("https://localhost:%d/api/v1/compliance-events/1", complianceAPIPort), nil,
165169
)
@@ -189,8 +193,10 @@ func bringDownDBConnection(ctx context.Context) {
189193
}
190194

191195
func restoreDBConnection(ctx context.Context) {
196+
GinkgoHelper()
197+
192198
By("Restoring the database connection")
193-
EventuallyWithOffset(1, func(g Gomega) {
199+
Eventually(func(g Gomega) {
194200
namespacedSecret := clientHub.CoreV1().Secrets("open-cluster-management")
195201
secret, err := namespacedSecret.Get(
196202
ctx, complianceeventsapi.DBSecretName, metav1.GetOptions{},
@@ -208,7 +214,7 @@ func restoreDBConnection(ctx context.Context) {
208214
}, defaultTimeoutSeconds, 1).Should(Succeed())
209215

210216
By("Waiting for the database connection to be up")
211-
EventuallyWithOffset(1, func(g Gomega) {
217+
Eventually(func(g Gomega) {
212218
req, err := http.NewRequestWithContext(
213219
ctx,
214220
http.MethodGet,

test/e2e/case5_policy_automation_test.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@ var _ = Describe("Test policy automation", Label("policyautomation"), Ordered, f
3030
ansiblelistlen := 0
3131
// Use this only when target_clusters managed1 managed2 managed3
3232
getLastAnsiblejob := func() *unstructured.Unstructured {
33+
GinkgoHelper()
34+
3335
ansiblejobList, err := clientHubDynamic.Resource(gvrAnsibleJob).Namespace(testNamespace).List(
3436
context.TODO(), metav1.ListOptions{},
3537
)
36-
ExpectWithOffset(1, err).ToNot(HaveOccurred())
38+
Expect(err).ToNot(HaveOccurred())
3739
for _, ansiblejob := range ansiblejobList.Items {
3840
targetClusters, _, err := unstructured.NestedSlice(ansiblejob.Object,
3941
"spec", "extra_vars", "target_clusters")
4042
if err != nil {
41-
ExpectWithOffset(1, err).ToNot(HaveOccurred())
43+
Expect(err).ToNot(HaveOccurred())
4244
}
4345
for _, clusterName := range targetClusters {
4446
if clusterName == "managed3" {
@@ -50,10 +52,12 @@ var _ = Describe("Test policy automation", Label("policyautomation"), Ordered, f
5052
return nil
5153
}
5254
getLastAnsiblejobByTime := func() *unstructured.Unstructured {
55+
GinkgoHelper()
56+
5357
ansiblejobList, err := clientHubDynamic.Resource(gvrAnsibleJob).Namespace(testNamespace).List(
5458
context.TODO(), metav1.ListOptions{},
5559
)
56-
ExpectWithOffset(1, err).ToNot(HaveOccurred())
60+
Expect(err).ToNot(HaveOccurred())
5761
sort.Slice(ansiblejobList.Items, func(i, j int) bool {
5862
p1 := ansiblejobList.Items[i].GetCreationTimestamp()
5963
p2 := ansiblejobList.Items[j].GetCreationTimestamp()

test/utils/utils.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,15 @@ func GetClusterLevelWithTimeout(
136136
wantFound bool,
137137
timeout int,
138138
) *unstructured.Unstructured {
139+
GinkgoHelper()
140+
139141
if timeout < 1 {
140142
timeout = 1
141143
}
142144

143145
var obj *unstructured.Unstructured
144146

145-
EventuallyWithOffset(1, func() error {
147+
Eventually(func() error {
146148
var err error
147149
namespace := clientHubDynamic.Resource(gvr)
148150

@@ -178,13 +180,15 @@ func GetWithTimeout(
178180
wantFound bool,
179181
timeout int,
180182
) *unstructured.Unstructured {
183+
GinkgoHelper()
184+
181185
if timeout < 1 {
182186
timeout = 1
183187
}
184188

185189
var obj *unstructured.Unstructured
186190

187-
EventuallyWithOffset(1, func() error {
191+
Eventually(func() error {
188192
var err error
189193
namespace := clientHubDynamic.Resource(gvr).Namespace(namespace)
190194

@@ -221,13 +225,15 @@ func ListWithTimeout(
221225
wantFound bool,
222226
timeout int,
223227
) *unstructured.UnstructuredList {
228+
GinkgoHelper()
229+
224230
if timeout < 1 {
225231
timeout = 1
226232
}
227233

228234
var list *unstructured.UnstructuredList
229235

230-
EventuallyWithOffset(1, func() error {
236+
Eventually(func() error {
231237
var err error
232238
list, err = clientHubDynamic.Resource(gvr).List(context.TODO(), opts)
233239
if err != nil {
@@ -259,13 +265,15 @@ func ListWithTimeoutByNamespace(
259265
wantFound bool,
260266
timeout int,
261267
) *unstructured.UnstructuredList {
268+
GinkgoHelper()
269+
262270
if timeout < 1 {
263271
timeout = 1
264272
}
265273

266274
var list *unstructured.UnstructuredList
267275

268-
EventuallyWithOffset(1, func() error {
276+
Eventually(func() error {
269277
var err error
270278
list, err = clientHubDynamic.Resource(gvr).Namespace(ns).List(context.TODO(), opts)
271279
if err != nil {
@@ -364,9 +372,11 @@ func GetMetrics(metricPatterns ...string) []string {
364372
func GetMatchingEvents(
365373
client kubernetes.Interface, namespace, objName, reasonRegex, msgRegex string, timeout int,
366374
) []corev1.Event {
375+
GinkgoHelper()
376+
367377
var eventList *corev1.EventList
368378

369-
EventuallyWithOffset(1, func() error {
379+
Eventually(func() error {
370380
var err error
371381
eventList, err = client.CoreV1().Events(namespace).List(context.TODO(), metav1.ListOptions{})
372382

0 commit comments

Comments
 (0)