From 3d5b3d63c69f0abc1630f0fb9a780f69e7f0b001 Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 4 May 2026 13:54:07 +0200 Subject: [PATCH] test(api/v2): use huma.ErrorModel for problem+json assertions --- pkg/webtests/huma_errors_test.go | 5 +++-- pkg/webtests/huma_label_test.go | 13 ------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/pkg/webtests/huma_errors_test.go b/pkg/webtests/huma_errors_test.go index 3ed853d1d..410c4f8af 100644 --- a/pkg/webtests/huma_errors_test.go +++ b/pkg/webtests/huma_errors_test.go @@ -22,6 +22,7 @@ import ( "strings" "testing" + "github.com/danielgtaylor/huma/v2" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -43,7 +44,7 @@ func TestHuma_ErrorShapeIsRFC9457(t *testing.T) { ct := rec.Header().Get("Content-Type") assert.Contains(t, ct, "application/problem+json", "forbidden response must use RFC 9457 content type; got %q", ct) - var body humaErrorBody + var body huma.ErrorModel require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &body), "body: %s", rec.Body.String()) assert.Equal(t, http.StatusForbidden, body.Status) assert.NotEmpty(t, body.Title, "title is required by RFC 9457") @@ -56,7 +57,7 @@ func TestHuma_ErrorShapeIsRFC9457(t *testing.T) { ct := rec.Header().Get("Content-Type") assert.Contains(t, ct, "application/problem+json", "validation response must use RFC 9457 content type; got %q", ct) - var body humaErrorBody + var body huma.ErrorModel require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &body), "body: %s", rec.Body.String()) assert.Equal(t, http.StatusUnprocessableEntity, body.Status) require.NotEmpty(t, body.Errors, "validation errors must include structured per-field details") diff --git a/pkg/webtests/huma_label_test.go b/pkg/webtests/huma_label_test.go index 897e30599..36f383bd4 100644 --- a/pkg/webtests/huma_label_test.go +++ b/pkg/webtests/huma_label_test.go @@ -41,19 +41,6 @@ func labelTokenFor(t *testing.T, u *user.User) string { return tok } -// humaErrorBody is the RFC 9457 problem+json shape Huma emits by default. -// Fields are a subset — we only assert what's load-bearing for the tests. -type humaErrorBody struct { - Type string `json:"type"` - Title string `json:"title"` - Status int `json:"status"` - Detail string `json:"detail"` - Errors []struct { - Message string `json:"message"` - Location string `json:"location"` - } `json:"errors"` -} - // TestHumaLabel mirrors the v1 webtest shape (see project_test.go's TestProject) // so the v2 contract can be read side-by-side with the v1 coverage. The goal // is to prove v2 is behaviourally compatible with v1 modulo the documented