MCPcopy Index your code
hub / github.com/kubernetes/sample-controller / runController

Method runController

controller_test.go:120–163  ·  view source on GitHub ↗
(ctx context.Context, fooRef cache.ObjectName, startInformers bool, expectError bool)

Source from the content-addressed store, hash-verified

118}
119
120func (f *fixture) runController(ctx context.Context, fooRef cache.ObjectName, startInformers bool, expectError bool) {
121 c, i, k8sI := f.newController(ctx)
122 if startInformers {
123 i.Start(ctx.Done())
124 k8sI.Start(ctx.Done())
125 }
126
127 err := c.syncHandler(ctx, fooRef)
128 if !expectError && err != nil {
129 f.t.Errorf("error syncing foo: %v", err)
130 } else if expectError && err == nil {
131 f.t.Error("expected error syncing foo, got nil")
132 }
133
134 actions := filterInformerActions(f.client.Actions())
135 for i, action := range actions {
136 if len(f.actions) < i+1 {
137 f.t.Errorf("%d unexpected actions: %+v", len(actions)-len(f.actions), actions[i:])
138 break
139 }
140
141 expectedAction := f.actions[i]
142 checkAction(expectedAction, action, f.t)
143 }
144
145 if len(f.actions) > len(actions) {
146 f.t.Errorf("%d additional expected actions:%+v", len(f.actions)-len(actions), f.actions[len(actions):])
147 }
148
149 k8sActions := filterInformerActions(f.kubeclient.Actions())
150 for i, action := range k8sActions {
151 if len(f.kubeactions) < i+1 {
152 f.t.Errorf("%d unexpected actions: %+v", len(k8sActions)-len(f.kubeactions), k8sActions[i:])
153 break
154 }
155
156 expectedAction := f.kubeactions[i]
157 checkAction(expectedAction, action, f.t)
158 }
159
160 if len(f.kubeactions) > len(k8sActions) {
161 f.t.Errorf("%d additional expected actions:%+v", len(f.kubeactions)-len(k8sActions), f.kubeactions[len(k8sActions):])
162 }
163}
164
165// checkAction verifies that expected and actual actions are equal and both have
166// same attached resources

Callers 2

runMethod · 0.95
runExpectErrorMethod · 0.95

Calls 5

newControllerMethod · 0.95
filterInformerActionsFunction · 0.85
checkActionFunction · 0.85
syncHandlerMethod · 0.80
StartMethod · 0.65

Tested by

no test coverage detected