| 47 | } |
| 48 | |
| 49 | func TestWriteErrorCode(t *testing.T) { |
| 50 | ctx := context.TODO() |
| 51 | w := httptest.NewRecorder() |
| 52 | |
| 53 | UserError(ctx, w, usererror.Newf(418, "pc load letter %d", 1)) |
| 54 | |
| 55 | if got, want := w.Code, 418; want != got { |
| 56 | t.Errorf("Want response code %d, got %d", want, got) |
| 57 | } |
| 58 | |
| 59 | errjson := &usererror.Error{} |
| 60 | if err := json.NewDecoder(w.Body).Decode(errjson); err != nil { |
| 61 | t.Error(err) |
| 62 | } |
| 63 | if got, want := errjson.Message, "pc load letter 1"; got != want { |
| 64 | t.Errorf("Want error message %s, got %s", want, got) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | func TestWriteNotFound(t *testing.T) { |
| 69 | ctx := context.TODO() |