client-go/rest: add TestWatchListWhenFeatureGateDisabled unit test

Kubernetes-commit: 8c0c1f720182f138c3151d3d67a80fa67b86a240
This commit is contained in:
Lukasz Szaszkiewicz 2024-05-23 16:33:43 +02:00 committed by Kubernetes Publisher
parent e8eae94e45
commit e89e40c187

View File

@ -31,6 +31,8 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/watch"
clientfeatures "k8s.io/client-go/features"
clientfeaturestesting "k8s.io/client-go/features/testing"
)
func TestWatchListResult(t *testing.T) {
@ -320,6 +322,22 @@ func TestWatchListFailure(t *testing.T) {
}
}
func TestWatchListWhenFeatureGateDisabled(t *testing.T) {
clientfeaturestesting.SetFeatureDuringTest(t, clientfeatures.WatchListClient, false)
expectedError := fmt.Errorf("%q feature gate is not enabled", clientfeatures.WatchListClient)
target := &Request{}
res := target.WatchList(context.TODO())
resErr := res.Into(nil)
if resErr == nil {
t.Fatal("expected to get an error, got nil")
}
if resErr.Error() != expectedError.Error() {
t.Fatalf("unexpected error: %v, expected: %v", resErr, expectedError)
}
}
func makePod(rv uint64) *v1.Pod {
return &v1.Pod{
ObjectMeta: metav1.ObjectMeta{