(t *testing.T)
| 389 | } |
| 390 | |
| 391 | func 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 | } |
nothing calls this directly
no test coverage detected