From 481f49cd90a270684631308464f5d3f5b0cc899c Mon Sep 17 00:00:00 2001 From: Asklv Date: Tue, 2 Jul 2024 16:19:07 +0800 Subject: [PATCH] fix: fix paged list unit test. Signed-off-by: Asklv --- .../stats/nodelatencystats/rest_test.go | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/pkg/apiserver/registry/stats/nodelatencystats/rest_test.go b/pkg/apiserver/registry/stats/nodelatencystats/rest_test.go index 1915faacd4f..df3f4ffd840 100644 --- a/pkg/apiserver/registry/stats/nodelatencystats/rest_test.go +++ b/pkg/apiserver/registry/stats/nodelatencystats/rest_test.go @@ -19,6 +19,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "k8s.io/apimachinery/pkg/apis/meta/internalversion" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -159,6 +160,7 @@ func TestRESTList(t *testing.T) { tests := []struct { name string summary *statsv1alpha1.NodeLatencyStats + options *internalversion.ListOptions expectedObj runtime.Object expectedErr bool }{ @@ -168,6 +170,30 @@ func TestRESTList(t *testing.T) { ObjectMeta: metav1.ObjectMeta{Name: "node1"}, PeerNodeLatencyStats: nil, }, + options: &internalversion.ListOptions{ + Limit: 10, + Continue: "", + }, + expectedObj: &statsv1alpha1.NodeLatencyStatsList{ + Items: []statsv1alpha1.NodeLatencyStats{ + { + ObjectMeta: metav1.ObjectMeta{Name: "node1"}, + PeerNodeLatencyStats: nil, + }, + }, + }, + expectedErr: false, + }, + { + name: "list summary", + summary: &statsv1alpha1.NodeLatencyStats{ + ObjectMeta: metav1.ObjectMeta{Name: "node1"}, + PeerNodeLatencyStats: nil, + }, + options: &internalversion.ListOptions{ + Limit: 0, + Continue: "", + }, expectedObj: &statsv1alpha1.NodeLatencyStatsList{ Items: []statsv1alpha1.NodeLatencyStats{ { @@ -184,7 +210,7 @@ func TestRESTList(t *testing.T) { r := NewREST() _, err := r.Create(context.TODO(), tt.summary, nil, nil) assert.Nil(t, err) - obj, err := r.List(context.TODO(), nil) + obj, err := r.List(context.TODO(), tt.options) if tt.expectedErr { assert.NotNil(t, err) } else {