(t *testing.T)
| 36 | } |
| 37 | |
| 38 | func TestMapErrorToHTTPStatus(t *testing.T) { |
| 39 | tests := []struct { |
| 40 | name string |
| 41 | err error |
| 42 | expected int |
| 43 | }{ |
| 44 | { |
| 45 | name: "NotFound Error", |
| 46 | err: apierror.NewAPIError(apierror.ErrNotFound, "Resource not found", nil), |
| 47 | expected: http.StatusNotFound, |
| 48 | }, |
| 49 | { |
| 50 | name: "Conflict Error", |
| 51 | err: apierror.NewAPIError(apierror.ErrConflict, "Conflict occurred", nil), |
| 52 | expected: http.StatusConflict, |
| 53 | }, |
| 54 | { |
| 55 | name: "InvalidInput Error", |
| 56 | err: apierror.NewAPIError(apierror.ErrInvalidInput, "Invalid input", nil), |
| 57 | expected: http.StatusBadRequest, |
| 58 | }, |
| 59 | { |
| 60 | name: "InternalServerError", |
| 61 | err: apierror.NewAPIError(apierror.ErrInternalServer, "Internal server error", nil), |
| 62 | expected: http.StatusInternalServerError, |
| 63 | }, |
| 64 | { |
| 65 | name: "Unknown Error", |
| 66 | err: errors.New("Unknown error"), |
| 67 | expected: http.StatusInternalServerError, |
| 68 | }, |
| 69 | } |
| 70 | |
| 71 | for _, tt := range tests { |
| 72 | t.Run(tt.name, func(t *testing.T) { |
| 73 | statusCode := apierror.MapErrorToHTTPStatus(tt.err) |
| 74 | assert.Equal(t, tt.expected, statusCode) |
| 75 | }) |
| 76 | } |
| 77 | } |
nothing calls this directly
no test coverage detected