| 392 | } |
| 393 | |
| 394 | func 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 { |