MCPcopy
hub / github.com/kubernetes/client-go / TestReflectorWatchListPageSize

Function TestReflectorWatchListPageSize

tools/cache/reflector_test.go:391–432  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

389}
390
391func TestReflectorWatchListPageSize(t *testing.T) {
392 stopCh := make(chan struct{})
393 s := NewStore(MetaNamespaceKeyFunc)
394
395 lw := &testLW{
396 WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
397 // Stop once the reflector begins watching since we're only interested in the list.
398 close(stopCh)
399 fw := watch.NewFake()
400 return fw, nil
401 },
402 ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
403 if options.Limit != 4 {
404 t.Fatalf("Expected list Limit of 4 but got %d", options.Limit)
405 }
406 pods := make([]v1.Pod, 10)
407 for i := 0; i < 10; i++ {
408 pods[i] = v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("pod-%d", i), ResourceVersion: fmt.Sprintf("%d", i)}}
409 }
410 switch options.Continue {
411 case "":
412 return &v1.PodList{ListMeta: metav1.ListMeta{ResourceVersion: "10", Continue: "C1"}, Items: pods[0:4]}, nil
413 case "C1":
414 return &v1.PodList{ListMeta: metav1.ListMeta{ResourceVersion: "10", Continue: "C2"}, Items: pods[4:8]}, nil
415 case "C2":
416 return &v1.PodList{ListMeta: metav1.ListMeta{ResourceVersion: "10"}, Items: pods[8:10]}, nil
417 default:
418 t.Fatalf("Unrecognized continue: %s", options.Continue)
419 }
420 return nil, nil
421 },
422 }
423 r := NewReflector(lw, &v1.Pod{}, s, 0)
424 // Set the reflector to paginate the list request in 4 item chunks.
425 r.WatchListPageSize = 4
426 r.ListAndWatch(stopCh)
427
428 results := s.List()
429 if len(results) != 10 {
430 t.Errorf("Expected 10 results, got %d", len(results))
431 }
432}

Callers

nothing calls this directly

Calls 5

ListAndWatchMethod · 0.95
ListMethod · 0.95
NewStoreFunction · 0.85
NewReflectorFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected