Skip to content

Commit f7feb19

Browse files
committed
Update snippets filter functional test
1 parent 67bb174 commit f7feb19

File tree

1 file changed

+63
-82
lines changed

1 file changed

+63
-82
lines changed

tests/suite/snippets_filter_test.go

Lines changed: 63 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
core "k8s.io/api/core/v1"
1111
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1212
"k8s.io/apimachinery/pkg/types"
13-
"k8s.io/apimachinery/pkg/util/wait"
1413
"sigs.k8s.io/controller-runtime/pkg/client"
1514
v1 "sigs.k8s.io/gateway-api/apis/v1"
1615

@@ -80,8 +79,11 @@ var _ = Describe("SnippetsFilter", Ordered, Label("functional", "snippets-filter
8079
for _, name := range snippetsFilterNames {
8180
nsname := types.NamespacedName{Name: name, Namespace: namespace}
8281

83-
err := waitForSnippetsFilterToBeAccepted(nsname)
84-
Expect(err).ToNot(HaveOccurred(), fmt.Sprintf("%s was not accepted", name))
82+
Eventually(checkForSnippetsFilterToBeAccepted).
83+
WithArguments(nsname).
84+
WithTimeout(timeoutConfig.GetStatusTimeout).
85+
WithPolling(500*time.Millisecond).
86+
Should(Succeed(), fmt.Sprintf("%s was not accepted", name))
8587
}
8688
})
8789

@@ -228,7 +230,7 @@ var _ = Describe("SnippetsFilter", Ordered, Label("functional", "snippets-filter
228230
Expect(resourceManager.ApplyFromFiles(files, namespace)).To(Succeed())
229231

230232
nsname := types.NamespacedName{Name: "tea", Namespace: namespace}
231-
Eventually(waitForHTTPRouteToHaveGatewayNotProgrammedCond).
233+
Eventually(checkHTTPRouteToHaveGatewayNotProgrammedCond).
232234
WithArguments(nsname).
233235
WithTimeout(timeoutConfig.GetStatusTimeout).
234236
WithPolling(500 * time.Millisecond).
@@ -243,7 +245,7 @@ var _ = Describe("SnippetsFilter", Ordered, Label("functional", "snippets-filter
243245
Expect(resourceManager.ApplyFromFiles(files, namespace)).To(Succeed())
244246

245247
nsname := types.NamespacedName{Name: "soda", Namespace: namespace}
246-
Eventually(waitForHTTPRouteToHaveGatewayNotProgrammedCond).
248+
Eventually(checkHTTPRouteToHaveGatewayNotProgrammedCond).
247249
WithArguments(nsname).
248250
WithTimeout(timeoutConfig.GetStatusTimeout).
249251
WithPolling(500 * time.Millisecond).
@@ -254,109 +256,88 @@ var _ = Describe("SnippetsFilter", Ordered, Label("functional", "snippets-filter
254256
})
255257
})
256258

257-
func waitForHTTPRouteToHaveGatewayNotProgrammedCond(httpRouteNsName types.NamespacedName) error {
258-
ctx, cancel := context.WithTimeout(context.Background(), timeoutConfig.GetStatusTimeout*2)
259+
func checkHTTPRouteToHaveGatewayNotProgrammedCond(httpRouteNsName types.NamespacedName) error {
260+
ctx, cancel := context.WithTimeout(context.Background(), timeoutConfig.GetTimeout)
259261
defer cancel()
260262

261263
GinkgoWriter.Printf(
262-
"Waiting for HTTPRoute %q to have the condition Accepted/True/GatewayNotProgrammed\n",
264+
"Checking for HTTPRoute %q to have the condition Accepted/True/GatewayNotProgrammed\n",
263265
httpRouteNsName,
264266
)
265267

266-
return wait.PollUntilContextCancel(
267-
ctx,
268-
500*time.Millisecond,
269-
true, /* poll immediately */
270-
func(ctx context.Context) (bool, error) {
271-
var hr v1.HTTPRoute
272-
var err error
268+
var hr v1.HTTPRoute
269+
var err error
273270

274-
if err = k8sClient.Get(ctx, httpRouteNsName, &hr); err != nil {
275-
return false, err
276-
}
271+
if err = k8sClient.Get(ctx, httpRouteNsName, &hr); err != nil {
272+
return err
273+
}
277274

278-
if len(hr.Status.Parents) == 0 {
279-
return false, nil
280-
}
275+
if len(hr.Status.Parents) != 1 {
276+
return fmt.Errorf("httproute has %d parent statuses, expected 1", len(hr.Status.Parents))
277+
}
281278

282-
if len(hr.Status.Parents) != 1 {
283-
return false, fmt.Errorf("httproute has %d parent statuses, expected 1", len(hr.Status.Parents))
284-
}
279+
parent := hr.Status.Parents[0]
280+
if parent.Conditions == nil {
281+
return fmt.Errorf("expected parent conditions to not be nil")
282+
}
285283

286-
parent := hr.Status.Parents[0]
287-
if parent.Conditions == nil {
288-
return false, fmt.Errorf("expected parent conditions to not be nil")
289-
}
284+
cond := parent.Conditions[1]
285+
if cond.Type != string(v1.GatewayConditionAccepted) {
286+
return fmt.Errorf("expected condition type to be Accepted, got %s", cond.Type)
287+
}
290288

291-
cond := parent.Conditions[1]
292-
if cond.Type != string(v1.GatewayConditionAccepted) {
293-
return false, fmt.Errorf("expected condition type to be Accepted, got %s", cond.Type)
294-
}
289+
if cond.Status != metav1.ConditionFalse {
290+
return fmt.Errorf("expected condition status to be False, got %s", cond.Status)
291+
}
295292

296-
if cond.Status != metav1.ConditionFalse {
297-
return false, fmt.Errorf("expected condition status to be False, got %s", cond.Status)
298-
}
293+
if cond.Reason != string(conditions.RouteReasonGatewayNotProgrammed) {
294+
return fmt.Errorf("expected condition reason to be GatewayNotProgrammed, got %s", cond.Reason)
295+
}
299296

300-
if cond.Reason != string(conditions.RouteReasonGatewayNotProgrammed) {
301-
return false, fmt.Errorf("expected condition reason to be GatewayNotProgrammed, got %s", cond.Reason)
302-
}
303-
return err == nil, err
304-
},
305-
)
297+
return nil
306298
}
307299

308-
func waitForSnippetsFilterToBeAccepted(snippetsFilterNsNames types.NamespacedName) error {
309-
ctx, cancel := context.WithTimeout(context.Background(), timeoutConfig.GetStatusTimeout)
300+
func checkForSnippetsFilterToBeAccepted(snippetsFilterNsNames types.NamespacedName) error {
301+
ctx, cancel := context.WithTimeout(context.Background(), timeoutConfig.GetTimeout)
310302
defer cancel()
311303

312304
GinkgoWriter.Printf(
313-
"Waiting for SnippetsFilter %q to have the condition Accepted/True/Accepted\n",
305+
"Checking for SnippetsFilter %q to have the condition Accepted/True/Accepted\n",
314306
snippetsFilterNsNames,
315307
)
316308

317-
return wait.PollUntilContextCancel(
318-
ctx,
319-
500*time.Millisecond,
320-
true, /* poll immediately */
321-
func(ctx context.Context) (bool, error) {
322-
var sf ngfAPI.SnippetsFilter
323-
var err error
309+
var sf ngfAPI.SnippetsFilter
310+
var err error
324311

325-
if err = k8sClient.Get(ctx, snippetsFilterNsNames, &sf); err != nil {
326-
return false, err
327-
}
312+
if err = k8sClient.Get(ctx, snippetsFilterNsNames, &sf); err != nil {
313+
return err
314+
}
328315

329-
if len(sf.Status.Controllers) == 0 {
330-
return false, nil
331-
}
332-
333-
if len(sf.Status.Controllers) != 1 {
334-
return false, fmt.Errorf("snippetsFilter has %d controller statuses, expected 1", len(sf.Status.Controllers))
335-
}
316+
if len(sf.Status.Controllers) != 1 {
317+
return fmt.Errorf("snippetsFilter has %d controller statuses, expected 1", len(sf.Status.Controllers))
318+
}
336319

337-
status := sf.Status.Controllers[0]
338-
if status.ControllerName != ngfControllerName {
339-
return false, fmt.Errorf("expected controller name to be %s, got %s", ngfControllerName, status.ControllerName)
340-
}
320+
status := sf.Status.Controllers[0]
321+
if status.ControllerName != ngfControllerName {
322+
return fmt.Errorf("expected controller name to be %s, got %s", ngfControllerName, status.ControllerName)
323+
}
341324

342-
condition := status.Conditions[0]
343-
if condition.Type != string(ngfAPI.SnippetsFilterConditionTypeAccepted) {
344-
return false, fmt.Errorf("expected condition type to be Accepted, got %s", condition.Type)
345-
}
325+
condition := status.Conditions[0]
326+
if condition.Type != string(ngfAPI.SnippetsFilterConditionTypeAccepted) {
327+
return fmt.Errorf("expected condition type to be Accepted, got %s", condition.Type)
328+
}
346329

347-
if status.Conditions[0].Status != metav1.ConditionTrue {
348-
return false, fmt.Errorf("expected condition status to be %s, got %s", metav1.ConditionTrue, condition.Status)
349-
}
330+
if status.Conditions[0].Status != metav1.ConditionTrue {
331+
return fmt.Errorf("expected condition status to be %s, got %s", metav1.ConditionTrue, condition.Status)
332+
}
350333

351-
if status.Conditions[0].Reason != string(ngfAPI.SnippetsFilterConditionReasonAccepted) {
352-
return false, fmt.Errorf(
353-
"expected condition reason to be %s, got %s",
354-
ngfAPI.SnippetsFilterConditionReasonAccepted,
355-
condition.Reason,
356-
)
357-
}
334+
if status.Conditions[0].Reason != string(ngfAPI.SnippetsFilterConditionReasonAccepted) {
335+
return fmt.Errorf(
336+
"expected condition reason to be %s, got %s",
337+
ngfAPI.SnippetsFilterConditionReasonAccepted,
338+
condition.Reason,
339+
)
340+
}
358341

359-
return err == nil, err
360-
},
361-
)
342+
return nil
362343
}

0 commit comments

Comments
 (0)