Skip to content

Commit

Permalink
fix: fix paged list unit test.
Browse files Browse the repository at this point in the history
Signed-off-by: Asklv <[email protected]>
  • Loading branch information
IRONICBo committed Jul 2, 2024
1 parent 3e54c05 commit 481f49c
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion pkg/apiserver/registry/stats/nodelatencystats/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -159,6 +160,7 @@ func TestRESTList(t *testing.T) {
tests := []struct {
name string
summary *statsv1alpha1.NodeLatencyStats
options *internalversion.ListOptions
expectedObj runtime.Object
expectedErr bool
}{
Expand All @@ -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{
{
Expand All @@ -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 {
Expand Down

0 comments on commit 481f49c

Please sign in to comment.