diff --git a/conformance/utils/kubernetes/helpers.go b/conformance/utils/kubernetes/helpers.go index d5446506e6..8596ceda4c 100644 --- a/conformance/utils/kubernetes/helpers.go +++ b/conformance/utils/kubernetes/helpers.go @@ -32,7 +32,6 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" "sigs.k8s.io/controller-runtime/pkg/client" @@ -636,12 +635,20 @@ func listenersMatch(t *testing.T, expected, actual []v1beta1.ListenerStatus) boo // Ensure that the expected Listener.SupportedKinds items are present in actual Listener.SupportedKinds // Find the items instead of performing an exact match of the slice because the implementation // might support more Kinds than defined in the test - eSupportedKindsSet := sets.New(eListener.SupportedKinds...) - aSupportedKindsSet := sets.New(aListener.SupportedKinds...) - if !aSupportedKindsSet.IsSuperset(eSupportedKindsSet) { - t.Logf("Expected %v kinds to be present in SupportedKinds", eSupportedKindsSet.Difference(aSupportedKindsSet)) - return false + for _, eKind := range eListener.SupportedKinds { + found := false + for _, aKind := range aListener.SupportedKinds { + if eKind.Group == aKind.Group && eKind.Kind == aKind.Kind { + found = true + break + } + } + if !found { + t.Logf("Expected Group:%s Kind:%s to be present in SupportedKinds", eKind.Group, eKind.Kind) + return false + } } + if aListener.AttachedRoutes != eListener.AttachedRoutes { t.Logf("Expected AttachedRoutes to be %v, got %v", eListener.AttachedRoutes, aListener.AttachedRoutes) return false diff --git a/conformance/utils/kubernetes/helpers_test.go b/conformance/utils/kubernetes/helpers_test.go new file mode 100644 index 0000000000..8fb2bea01f --- /dev/null +++ b/conformance/utils/kubernetes/helpers_test.go @@ -0,0 +1,54 @@ +package kubernetes + +import ( + "k8s.io/apimachinery/pkg/util/sets" + "sigs.k8s.io/gateway-api/apis/v1beta1" + "testing" +) + +func TestSupportedKindsStringSet(t *testing.T) { + t.Helper() + eSupportedKinds := []v1beta1.RouteGroupKind{{ + Group: (*v1beta1.Group)(&v1beta1.GroupVersion.Group), + Kind: v1beta1.Kind("HTTPRoute"), + }} + aSupportedKinds := []v1beta1.RouteGroupKind{{ + Group: (*v1beta1.Group)(&v1beta1.GroupVersion.Group), + Kind: v1beta1.Kind("HTTPRoute"), + }} + eSupportedKindsSet := sets.NewString() + aSupportedKindsSet := sets.NewString() + for _, eKind := range eSupportedKinds { + eSupportedKindsSet.Insert(string(eKind.Kind)) + } + for _, aKind := range aSupportedKinds { + aSupportedKindsSet.Insert(string(aKind.Kind)) + } + if !aSupportedKindsSet.IsSuperset(eSupportedKindsSet) { + t.Logf("Expected %v kinds to be present in SupportedKinds", eSupportedKindsSet.Difference(aSupportedKindsSet)) + } +} + +func TestSupportedKindsGenericSet(t *testing.T) { + t.Helper() + eSupportedKinds := []v1beta1.RouteGroupKind{{ + Group: (*v1beta1.Group)(&v1beta1.GroupVersion.Group), + Kind: v1beta1.Kind("HTTPRoute"), + }} + aSupportedKinds := []v1beta1.RouteGroupKind{ + { + Group: (*v1beta1.Group)(&v1beta1.GroupVersion.Group), + Kind: v1beta1.Kind("HTTPRoute"), + }, + { + Group: (*v1beta1.Group)(&v1beta1.GroupVersion.Group), + Kind: v1beta1.Kind("GRPCRoute"), + }, + } + + eSupportedKindsSet := sets.New(eSupportedKinds...) + aSupportedKindsSet := sets.New(aSupportedKinds...) + // if !aSupportedKindsSet.IsSuperset(eSupportedKindsSet) { + t.Fatalf("Expected %v kinds to be present in SupportedKinds", eSupportedKindsSet.Difference(aSupportedKindsSet)) + // } +}