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

Function TestUpdate

deprecated-dynamic/client_test.go:394–467  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

392}
393
394func TestUpdate(t *testing.T) {
395 tcs := []struct {
396 resource string
397 name string
398 namespace string
399 obj *unstructured.Unstructured
400 path string
401 }{
402 {
403 resource: "rtest",
404 name: "normal_update",
405 path: "/apis/gtest/vtest/rtest/normal_update",
406 obj: getObject("gtest/vTest", "rTest", "normal_update"),
407 },
408 {
409 resource: "rtest",
410 name: "namespaced_update",
411 namespace: "nstest",
412 path: "/apis/gtest/vtest/namespaces/nstest/rtest/namespaced_update",
413 obj: getObject("gtest/vTest", "rTest", "namespaced_update"),
414 },
415 {
416 resource: "rtest/srtest",
417 name: "normal_subresource_update",
418 path: "/apis/gtest/vtest/rtest/normal_update/srtest",
419 obj: getObject("gtest/vTest", "srTest", "normal_update"),
420 },
421 {
422 resource: "rtest/srtest",
423 name: "namespaced_subresource_update",
424 namespace: "nstest",
425 path: "/apis/gtest/vtest/namespaces/nstest/rtest/namespaced_update/srtest",
426 obj: getObject("gtest/vTest", "srTest", "namespaced_update"),
427 },
428 }
429 for _, tc := range tcs {
430 gv := &schema.GroupVersion{Group: "gtest", Version: "vtest"}
431 resource := &metav1.APIResource{Name: tc.resource, Namespaced: len(tc.namespace) != 0}
432 cl, srv, err := getClientServer(gv, func(w http.ResponseWriter, r *http.Request) {
433 if r.Method != "PUT" {
434 t.Errorf("Update(%q) got HTTP method %s. wanted PUT", tc.name, r.Method)
435 }
436
437 if r.URL.Path != tc.path {
438 t.Errorf("Update(%q) got path %s. wanted %s", tc.name, r.URL.Path, tc.path)
439 }
440
441 w.Header().Set("Content-Type", runtime.ContentTypeJSON)
442 data, err := ioutil.ReadAll(r.Body)
443 if err != nil {
444 t.Errorf("Update(%q) unexpected error reading body: %v", tc.name, err)
445 w.WriteHeader(http.StatusInternalServerError)
446 return
447 }
448
449 w.Write(data)
450 })
451 if err != nil {

Callers

nothing calls this directly

Calls 8

WriteMethod · 0.80
getObjectFunction · 0.70
getClientServerFunction · 0.70
ErrorfMethod · 0.65
SetMethod · 0.65
CloseMethod · 0.65
UpdateMethod · 0.65
ResourceMethod · 0.65

Tested by

no test coverage detected