(t *testing.T)
| 737 | } |
| 738 | |
| 739 | func TestTransformUnstructuredError(t *testing.T) { |
| 740 | testCases := []struct { |
| 741 | Req *http.Request |
| 742 | Res *http.Response |
| 743 | |
| 744 | Resource string |
| 745 | Name string |
| 746 | |
| 747 | ErrFn func(error) bool |
| 748 | Transformed error |
| 749 | }{ |
| 750 | { |
| 751 | Resource: "foo", |
| 752 | Name: "bar", |
| 753 | Req: &http.Request{ |
| 754 | Method: "POST", |
| 755 | }, |
| 756 | Res: &http.Response{ |
| 757 | StatusCode: http.StatusConflict, |
| 758 | Body: ioutil.NopCloser(bytes.NewReader(nil)), |
| 759 | }, |
| 760 | ErrFn: apierrors.IsAlreadyExists, |
| 761 | }, |
| 762 | { |
| 763 | Resource: "foo", |
| 764 | Name: "bar", |
| 765 | Req: &http.Request{ |
| 766 | Method: "PUT", |
| 767 | }, |
| 768 | Res: &http.Response{ |
| 769 | StatusCode: http.StatusConflict, |
| 770 | Body: ioutil.NopCloser(bytes.NewReader(nil)), |
| 771 | }, |
| 772 | ErrFn: apierrors.IsConflict, |
| 773 | }, |
| 774 | { |
| 775 | Resource: "foo", |
| 776 | Name: "bar", |
| 777 | Req: &http.Request{}, |
| 778 | Res: &http.Response{ |
| 779 | StatusCode: http.StatusNotFound, |
| 780 | Body: ioutil.NopCloser(bytes.NewReader(nil)), |
| 781 | }, |
| 782 | ErrFn: apierrors.IsNotFound, |
| 783 | }, |
| 784 | { |
| 785 | Req: &http.Request{}, |
| 786 | Res: &http.Response{ |
| 787 | StatusCode: http.StatusBadRequest, |
| 788 | Body: ioutil.NopCloser(bytes.NewReader(nil)), |
| 789 | }, |
| 790 | ErrFn: apierrors.IsBadRequest, |
| 791 | }, |
| 792 | { |
| 793 | // status in response overrides transformed result |
| 794 | Req: &http.Request{}, |
| 795 | Res: &http.Response{StatusCode: http.StatusBadRequest, Body: ioutil.NopCloser(bytes.NewReader([]byte(`{"kind":"Status","apiVersion":"v1","status":"Failure","code":404}`)))}, |
| 796 | ErrFn: apierrors.IsBadRequest, |
nothing calls this directly
no test coverage detected