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

Function TestMutationDetector

tools/cache/mutation_detector_test.go:31–81  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29)
30
31func TestMutationDetector(t *testing.T) {
32 fakeWatch := watch.NewFake()
33 lw := &testLW{
34 WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
35 return fakeWatch, nil
36 },
37 ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
38 return &v1.PodList{}, nil
39 },
40 }
41 pod := &v1.Pod{
42 ObjectMeta: metav1.ObjectMeta{
43 Name: "anything",
44 Labels: map[string]string{"check": "foo"},
45 },
46 }
47 stopCh := make(chan struct{})
48 defer close(stopCh)
49 addReceived := make(chan bool)
50 mutationFound := make(chan bool)
51
52 informer := NewSharedInformer(lw, &v1.Pod{}, 1*time.Second).(*sharedIndexInformer)
53 informer.cacheMutationDetector = &defaultCacheMutationDetector{
54 name: "name",
55 period: 1 * time.Second,
56 failureFunc: func(message string) {
57 mutationFound <- true
58 },
59 }
60 informer.AddEventHandler(
61 ResourceEventHandlerFuncs{
62 AddFunc: func(obj interface{}) {
63 addReceived <- true
64 },
65 },
66 )
67 go informer.Run(stopCh)
68
69 fakeWatch.Add(pod)
70
71 select {
72 case <-addReceived:
73 }
74
75 pod.Labels["change"] = "true"
76
77 select {
78 case <-mutationFound:
79 }
80
81}

Callers

nothing calls this directly

Calls 4

NewSharedInformerFunction · 0.85
AddEventHandlerMethod · 0.65
RunMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected