| 61 | } |
| 62 | |
| 63 | func TestErrorHandler(t *testing.T) { |
| 64 | ctx, getError := NewContextWithErrorValue(test.Context()) |
| 65 | |
| 66 | err := errors.New("some_error") |
| 67 | |
| 68 | a := assertions.New(t) |
| 69 | r := httptest.NewRequest(http.MethodGet, "/", nil) |
| 70 | r = r.WithContext(ctx) |
| 71 | rec := httptest.NewRecorder() |
| 72 | |
| 73 | Error(rec, r, err) |
| 74 | |
| 75 | res := rec.Result() |
| 76 | a.So(res.StatusCode, should.Equal, http.StatusInternalServerError) |
| 77 | |
| 78 | body, _ := io.ReadAll(res.Body) |
| 79 | a.So(string(body), should.ContainSubstring, "some_error") |
| 80 | |
| 81 | a.So(getError(), should.EqualErrorOrDefinition, err) |
| 82 | } |