| 538 | } |
| 539 | |
| 540 | func TestPatch(t *testing.T) { |
| 541 | tcs := []struct { |
| 542 | resource string |
| 543 | name string |
| 544 | namespace string |
| 545 | patch []byte |
| 546 | want *unstructured.Unstructured |
| 547 | path string |
| 548 | }{ |
| 549 | { |
| 550 | resource: "rtest", |
| 551 | name: "normal_patch", |
| 552 | path: "/apis/gtest/vtest/rtest/normal_patch", |
| 553 | patch: getJSON("gtest/vTest", "rTest", "normal_patch"), |
| 554 | want: getObject("gtest/vTest", "rTest", "normal_patch"), |
| 555 | }, |
| 556 | { |
| 557 | resource: "rtest", |
| 558 | name: "namespaced_patch", |
| 559 | namespace: "nstest", |
| 560 | path: "/apis/gtest/vtest/namespaces/nstest/rtest/namespaced_patch", |
| 561 | patch: getJSON("gtest/vTest", "rTest", "namespaced_patch"), |
| 562 | want: getObject("gtest/vTest", "rTest", "namespaced_patch"), |
| 563 | }, |
| 564 | { |
| 565 | resource: "rtest/srtest", |
| 566 | name: "normal_subresource_patch", |
| 567 | path: "/apis/gtest/vtest/rtest/normal_subresource_patch/srtest", |
| 568 | patch: getJSON("gtest/vTest", "srTest", "normal_subresource_patch"), |
| 569 | want: getObject("gtest/vTest", "srTest", "normal_subresource_patch"), |
| 570 | }, |
| 571 | { |
| 572 | resource: "rtest/srtest", |
| 573 | name: "namespaced_subresource_patch", |
| 574 | namespace: "nstest", |
| 575 | path: "/apis/gtest/vtest/namespaces/nstest/rtest/namespaced_subresource_patch/srtest", |
| 576 | patch: getJSON("gtest/vTest", "srTest", "namespaced_subresource_patch"), |
| 577 | want: getObject("gtest/vTest", "srTest", "namespaced_subresource_patch"), |
| 578 | }, |
| 579 | } |
| 580 | for _, tc := range tcs { |
| 581 | gv := &schema.GroupVersion{Group: "gtest", Version: "vtest"} |
| 582 | resource := &metav1.APIResource{Name: tc.resource, Namespaced: len(tc.namespace) != 0} |
| 583 | cl, srv, err := getClientServer(gv, func(w http.ResponseWriter, r *http.Request) { |
| 584 | if r.Method != "PATCH" { |
| 585 | t.Errorf("Patch(%q) got HTTP method %s. wanted PATCH", tc.name, r.Method) |
| 586 | } |
| 587 | |
| 588 | if r.URL.Path != tc.path { |
| 589 | t.Errorf("Patch(%q) got path %s. wanted %s", tc.name, r.URL.Path, tc.path) |
| 590 | } |
| 591 | |
| 592 | content := r.Header.Get("Content-Type") |
| 593 | if content != string(types.StrategicMergePatchType) { |
| 594 | t.Errorf("Patch(%q) got Content-Type %s. wanted %s", tc.name, content, types.StrategicMergePatchType) |
| 595 | } |
| 596 | |
| 597 | data, err := ioutil.ReadAll(r.Body) |