Skip to content

Commit

Permalink
Add explicit equality checks for SupportedKinds
Browse files Browse the repository at this point in the history
Fixes: kubernetes-sigs#1703

Signed-off-by: Arko Dasgupta <arko@tetrate.io>
  • Loading branch information
arkodg committed Feb 7, 2023
1 parent e552a32 commit c437447
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 6 deletions.
19 changes: 13 additions & 6 deletions conformance/utils/kubernetes/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
54 changes: 54 additions & 0 deletions conformance/utils/kubernetes/helpers_test.go
Original file line number Diff line number Diff line change
@@ -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))
// }
}

0 comments on commit c437447

Please sign in to comment.