forked from kubernetes-sigs/gateway-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add explicit equality checks for SupportedKinds
Fixes: kubernetes-sigs#1703 Signed-off-by: Arko Dasgupta <arko@tetrate.io>
- Loading branch information
Showing
2 changed files
with
67 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
// } | ||
} |