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

Function TestWatchAddAfterStop

testing/fixture_test.go:232–261  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

230}
231
232func TestWatchAddAfterStop(t *testing.T) {
233 testResource := schema.GroupVersionResource{Group: "", Version: "test_version", Resource: "test_kind"}
234 testObj := getArbitraryResource(testResource, "test_name", "test_namespace")
235 accessor, err := meta.Accessor(testObj)
236 if err != nil {
237 t.Fatalf("unexpected error: %v", err)
238 }
239
240 ns := accessor.GetNamespace()
241 scheme := runtime.NewScheme()
242 codecs := serializer.NewCodecFactory(scheme)
243 o := NewObjectTracker(scheme, codecs.UniversalDecoder())
244 watch, err := o.Watch(testResource, ns)
245 if err != nil {
246 t.Errorf("watch creation failed: %v", err)
247 }
248
249 // When the watch is stopped it should ignore later events without panicking.
250 defer func() {
251 if r := recover(); r != nil {
252 t.Errorf("Watch panicked when it should have ignored create after stop: %v", r)
253 }
254 }()
255
256 watch.Stop()
257 err = o.Create(testResource, testObj, ns)
258 if err != nil {
259 t.Errorf("test resource creation failed: %v", err)
260 }
261}
262
263func TestPatchWithMissingObject(t *testing.T) {
264 nodesResource := schema.GroupVersionResource{Group: "", Version: "v1", Resource: "nodes"}

Callers

nothing calls this directly

Calls 7

WatchMethod · 0.95
CreateMethod · 0.95
getArbitraryResourceFunction · 0.85
NewObjectTrackerFunction · 0.85
GetNamespaceMethod · 0.65
ErrorfMethod · 0.65
StopMethod · 0.65

Tested by

no test coverage detected