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

Function TestRCNumber

tools/cache/testing/fake_controller_source_test.go:51–95  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

49}
50
51func TestRCNumber(t *testing.T) {
52 pod := func(name string) *v1.Pod {
53 return &v1.Pod{
54 ObjectMeta: metav1.ObjectMeta{
55 Name: name,
56 },
57 }
58 }
59
60 wg := &sync.WaitGroup{}
61 wg.Add(3)
62
63 source := NewFakeControllerSource()
64 source.Add(pod("foo"))
65 source.Modify(pod("foo"))
66 source.Modify(pod("foo"))
67
68 w, err := source.Watch(metav1.ListOptions{ResourceVersion: "1"})
69 if err != nil {
70 t.Fatalf("Unexpected error: %v", err)
71 }
72 go consume(t, w, []string{"2", "3"}, wg)
73
74 list, err := source.List(metav1.ListOptions{})
75 if err != nil {
76 t.Fatalf("Unexpected error: %v", err)
77 }
78 if e, a := "3", list.(*v1.List).ResourceVersion; e != a {
79 t.Errorf("wanted %v, got %v", e, a)
80 }
81
82 w2, err := source.Watch(metav1.ListOptions{ResourceVersion: "2"})
83 if err != nil {
84 t.Fatalf("Unexpected error: %v", err)
85 }
86 go consume(t, w2, []string{"3"}, wg)
87
88 w3, err := source.Watch(metav1.ListOptions{ResourceVersion: "3"})
89 if err != nil {
90 t.Fatalf("Unexpected error: %v", err)
91 }
92 go consume(t, w3, []string{}, wg)
93 source.Shutdown()
94 wg.Wait()
95}

Callers

nothing calls this directly

Calls 9

AddMethod · 0.95
ModifyMethod · 0.95
WatchMethod · 0.95
ListMethod · 0.95
ShutdownMethod · 0.95
NewFakeControllerSourceFunction · 0.85
consumeFunction · 0.85
AddMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected