Skip to content

Commit

Permalink
fix: flaky test fixed
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Lavacca <lavacca.mattia@gmail.com>
  • Loading branch information
mlavacca committed Nov 3, 2023
1 parent 18c4a3b commit 9b640b5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
4 changes: 1 addition & 3 deletions pkg/i2gw/providers/kong/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,7 @@ func Test_ToGateway(t *testing.T) {
key := types.NamespacedName{Namespace: got.Namespace, Name: got.Name}
want := tc.expectedGatewayResources.HTTPRoutes[key]
want.SetGroupVersionKind(common.HTTPRouteGVK)
if !apiequality.Semantic.DeepEqual(got, want) {
t.Errorf("Expected HTTPRoute %s to be %+v\n Got: %+v\n Diff: %s", i, want, got, cmp.Diff(want, got))
}
assertHTTPRoutesEqual(t, i, got, want)
}
}

Expand Down
40 changes: 39 additions & 1 deletion pkg/i2gw/providers/kong/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,45 @@ limitations under the License.

package kong

import gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
import (
"testing"

apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/types"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"

"github.com/google/go-cmp/cmp"
)

func assertHTTPRoutesEqual(t *testing.T, i types.NamespacedName, got, want gatewayv1beta1.HTTPRoute) {
if !apiequality.Semantic.DeepEqual(got.ObjectMeta, want.ObjectMeta) {
t.Errorf("Expected HTTPRoute ObjectMeta %s to be %+v\n Got: %+v\n Diff: %s", i, want.ObjectMeta, got.ObjectMeta, cmp.Diff(want.ObjectMeta, got.ObjectMeta))
}
if !apiequality.Semantic.DeepEqual(got.Spec.Hostnames, want.Spec.Hostnames) {
t.Errorf("Expected HTTPRoute %s to be %+v\n Got: %+v\n Diff: %s", i, want.Spec.Hostnames, got.Spec.Hostnames, cmp.Diff(want.Spec.Hostnames, got.Spec.Hostnames))
}
if !apiequality.Semantic.DeepEqual(got.Spec.ParentRefs, want.Spec.ParentRefs) {
t.Errorf("Expected HTTPRoute %s to be %+v\n Got: %+v\n Diff: %s", i, want.Spec.ParentRefs, got.Spec.ParentRefs, cmp.Diff(want.Spec.ParentRefs, got.Spec.ParentRefs))
}
for _, r := range want.Spec.Rules {
if !httpRouteRulesContainsRule(got.Spec.Rules, r) {
t.Errorf("Expected HTTPRoute %s to have rule %+v\n Got: %+v\n Diff: %s", i, got.Spec.Rules, r, cmp.Diff(want, got))
}
}
}

func httpRouteRulesContainsRule(httpRouteRules []gatewayv1beta1.HTTPRouteRule, rule gatewayv1beta1.HTTPRouteRule) bool {
var found bool
for _, r := range httpRouteRules {
if apiequality.Semantic.DeepEqual(r, rule) {
found = true
}
if found {
break
}
}
return found
}

func containsMatches(matches []gatewayv1beta1.HTTPRouteMatch, matchesToCheck []gatewayv1beta1.HTTPRouteMatch) bool {
if len(matches) != len(matchesToCheck) {
Expand Down

0 comments on commit 9b640b5

Please sign in to comment.