(t *testing.T, w *httptest.ResponseRecorder, wantStatus int, wantCode apperrors.ErrorCode)
| 327 | } |
| 328 | |
| 329 | func assertEnvelope(t *testing.T, w *httptest.ResponseRecorder, wantStatus int, wantCode apperrors.ErrorCode) { |
| 330 | t.Helper() |
| 331 | if w.Code != wantStatus { |
| 332 | t.Fatalf("status: got %d, want %d (body=%s)", w.Code, wantStatus, w.Body.String()) |
| 333 | } |
| 334 | var body struct { |
| 335 | Success bool `json:"success"` |
| 336 | Error struct { |
| 337 | Code apperrors.ErrorCode `json:"code"` |
| 338 | Message string `json:"message"` |
| 339 | } `json:"error"` |
| 340 | } |
| 341 | if err := json.Unmarshal(w.Body.Bytes(), &body); err != nil { |
| 342 | t.Fatalf("body is not the standard envelope: %v (body=%s)", err, w.Body.String()) |
| 343 | } |
| 344 | if body.Success { |
| 345 | t.Fatalf("envelope success must be false on rejection, got body=%s", w.Body.String()) |
| 346 | } |
| 347 | if body.Error.Code != wantCode { |
| 348 | t.Fatalf("envelope error.code: got %d, want %d (body=%s)", |
| 349 | body.Error.Code, wantCode, w.Body.String()) |
| 350 | } |
| 351 | if body.Error.Message == "" { |
| 352 | t.Fatalf("envelope error.message must be non-empty, got body=%s", w.Body.String()) |
| 353 | } |
| 354 | } |
no test coverage detected