(t *testing.T)
| 19 | ) |
| 20 | |
| 21 | func TestDefaultHTTPError(t *testing.T) { |
| 22 | ctx := context.Background() |
| 23 | |
| 24 | statusWithDetails, _ := status.New(codes.FailedPrecondition, "failed precondition").WithDetails( |
| 25 | &errdetails.PreconditionFailure{}, |
| 26 | ) |
| 27 | |
| 28 | for i, spec := range []struct { |
| 29 | err error |
| 30 | status int |
| 31 | msg string |
| 32 | marshaler runtime.Marshaler |
| 33 | contentType string |
| 34 | details string |
| 35 | fordwardRespRewriter runtime.ForwardResponseRewriter |
| 36 | extractMessage func(*testing.T) |
| 37 | }{ |
| 38 | { |
| 39 | err: errors.New("example error"), |
| 40 | status: http.StatusInternalServerError, |
| 41 | marshaler: &runtime.JSONPb{}, |
| 42 | contentType: "application/json", |
| 43 | msg: "example error", |
| 44 | }, |
| 45 | { |
| 46 | err: status.Error(codes.NotFound, "no such resource"), |
| 47 | status: http.StatusNotFound, |
| 48 | marshaler: &runtime.JSONPb{}, |
| 49 | contentType: "application/json", |
| 50 | msg: "no such resource", |
| 51 | }, |
| 52 | { |
| 53 | err: statusWithDetails.Err(), |
| 54 | status: http.StatusBadRequest, |
| 55 | marshaler: &runtime.JSONPb{}, |
| 56 | contentType: "application/json", |
| 57 | msg: "failed precondition", |
| 58 | details: "type.googleapis.com/google.rpc.PreconditionFailure", |
| 59 | }, |
| 60 | { |
| 61 | err: errors.New("example error"), |
| 62 | status: http.StatusInternalServerError, |
| 63 | marshaler: &CustomMarshaler{&runtime.JSONPb{}}, |
| 64 | contentType: "Custom-Content-Type", |
| 65 | msg: "example error", |
| 66 | }, |
| 67 | { |
| 68 | err: &runtime.HTTPStatusError{ |
| 69 | HTTPStatus: http.StatusMethodNotAllowed, |
| 70 | Err: status.Error(codes.Unimplemented, http.StatusText(http.StatusMethodNotAllowed)), |
| 71 | }, |
| 72 | status: http.StatusMethodNotAllowed, |
| 73 | marshaler: &runtime.JSONPb{}, |
| 74 | contentType: "application/json", |
| 75 | msg: "Method Not Allowed", |
| 76 | }, |
| 77 | { |
| 78 | err: status.Error(codes.InvalidArgument, "example error"), |
nothing calls this directly
no test coverage detected