mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 03:57:41 +00:00
Merge pull request #126854 from serathius/pagination-tests
Add paging tests
This commit is contained in:
commit
cee43048c7
@ -166,6 +166,12 @@ func TestPreconditionalDeleteWithSuggestionPass(t *testing.T) {
|
||||
storagetesting.RunTestPreconditionalDeleteWithOnlySuggestionPass(ctx, t, cacher)
|
||||
}
|
||||
|
||||
func TestListPaging(t *testing.T) {
|
||||
ctx, cacher, terminate := testSetup(t)
|
||||
t.Cleanup(terminate)
|
||||
storagetesting.RunTestListPaging(ctx, t, cacher)
|
||||
}
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.ConsistentListFromCache, false)
|
||||
ctx, cacher, server, terminate := testSetupWithEtcdServer(t)
|
||||
|
@ -161,6 +161,11 @@ func TestPreconditionalDeleteWithSuggestionPass(t *testing.T) {
|
||||
storagetesting.RunTestPreconditionalDeleteWithOnlySuggestionPass(ctx, t, store)
|
||||
}
|
||||
|
||||
func TestListPaging(t *testing.T) {
|
||||
ctx, store, _ := testSetup(t)
|
||||
storagetesting.RunTestListPaging(ctx, t, store)
|
||||
}
|
||||
|
||||
func TestGetListNonRecursive(t *testing.T) {
|
||||
ctx, store, client := testSetup(t)
|
||||
storagetesting.RunTestGetListNonRecursive(ctx, t, compactStorage(client), store)
|
||||
|
@ -2707,3 +2707,55 @@ func RunTestCount(ctx context.Context, t *testing.T, store storage.Interface) {
|
||||
t.Fatalf("store.Count for resource %s: expected %d but got %d", resourceA, resourceACountExpected, resourceACountGot)
|
||||
}
|
||||
}
|
||||
|
||||
func RunTestListPaging(ctx context.Context, t *testing.T, store storage.Interface) {
|
||||
out := &example.Pod{}
|
||||
for i := 0; i < 4; i++ {
|
||||
name := fmt.Sprintf("test-%d", i)
|
||||
pod := &example.Pod{ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: "paging"}}
|
||||
key := computePodKey(pod)
|
||||
if err := store.Create(ctx, key, pod, out, 0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
var names []string
|
||||
opts := storage.ListOptions{
|
||||
Recursive: true,
|
||||
Predicate: storage.SelectionPredicate{
|
||||
Label: labels.Everything(),
|
||||
Field: fields.Everything(),
|
||||
Limit: 1,
|
||||
},
|
||||
}
|
||||
calls := 0
|
||||
for {
|
||||
calls++
|
||||
listOut := &example.PodList{}
|
||||
err := store.GetList(ctx, "/pods", opts, listOut)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error %s", err)
|
||||
}
|
||||
for _, item := range listOut.Items {
|
||||
names = append(names, item.Name)
|
||||
}
|
||||
if listOut.Continue == "" {
|
||||
break
|
||||
}
|
||||
if calls == 2 {
|
||||
name := "test-5"
|
||||
pod := &example.Pod{ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: "paging"}}
|
||||
key := computePodKey(pod)
|
||||
if err := store.Create(ctx, key, pod, out, 0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
opts.Predicate.Continue = listOut.Continue
|
||||
}
|
||||
if calls != 4 {
|
||||
t.Errorf("unexpected list invocations: %d", calls)
|
||||
}
|
||||
if !reflect.DeepEqual(names, []string{"test-0", "test-1", "test-2", "test-3"}) {
|
||||
t.Errorf("unexpected items: %#v", names)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user