Skip to content

chore: Refactor HTTPRoute and HTTPRoutePolicy tests condition assertion #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: release-v2-dev
Choose a base branch
from
46 changes: 46 additions & 0 deletions test/e2e/framework/assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,52 @@ import (
"github.com/apache/apisix-ingress-controller/api/v1alpha1"
)

func GatewayClassMustHaveCondition(t testing.TestingT, cli client.Client, timeout time.Duration, gcNN types.NamespacedName, condition metav1.Condition) {
err := PollUntilGatewayClassMustHaveStatus(cli, timeout, gcNN, func(gc *gatewayv1.GatewayClass) bool {
if err := kubernetes.ConditionsHaveLatestObservedGeneration(gc, gc.Status.Conditions); err != nil {
log.Printf("GatewayClass %s %v", gcNN, err)
return false
}
if findConditionInList(gc.Status.Conditions, condition) {
return true
}
log.Printf("NOT FOUND condition %v in %v", condition, gc.Status.Conditions)
return false
})
require.NoError(t, err, "waiting for GatewayClass to have condition %+v", condition)
}

func PollUntilGatewayClassMustHaveStatus(cli client.Client, timeout time.Duration, gcNN types.NamespacedName, f func(gc *gatewayv1.GatewayClass) bool) error {
if err := gatewayv1.Install(cli.Scheme()); err != nil {
return err
}
return genericPollResource(new(gatewayv1.GatewayClass), cli, timeout, gcNN, f)
}

func GatewayMustHaveCondition(t testing.TestingT, cli client.Client, timeout time.Duration, gwNN types.NamespacedName, condition metav1.Condition) {
err := PollUntilGatewayHaveStatus(cli, timeout, gwNN, func(gw *gatewayv1.Gateway) bool {
if err := kubernetes.ConditionsHaveLatestObservedGeneration(gw, gw.Status.Conditions); err != nil {
log.Printf("Gateway %s %v", gwNN, err)
return false
}
if findConditionInList(gw.Status.Conditions, condition) {
log.Printf("found condition %v in list %v", condition, gw.Status.Conditions)
return true
} else {
log.Printf("NOT FOUND condition %v in %v", condition, gw.Status.Conditions)
return false
}
})
require.NoError(t, err, "waiting for Gateway to have condition %+v", condition)
}

func PollUntilGatewayHaveStatus(cli client.Client, timeout time.Duration, gwNN types.NamespacedName, f func(gateway *gatewayv1.Gateway) bool) error {
if err := gatewayv1.Install(cli.Scheme()); err != nil {
return err
}
return genericPollResource(new(gatewayv1.Gateway), cli, timeout, gwNN, f)
}

func HTTPRouteMustHaveCondition(t testing.TestingT, cli client.Client, timeout time.Duration, refNN, hrNN types.NamespacedName, condition metav1.Condition) {
err := PollUntilHTTPRouteHaveStatus(cli, timeout, hrNN, func(hr *gatewayv1.HTTPRoute) bool {
for _, parent := range hr.Status.Parents {
Expand Down
Loading
Loading