(t *testing.T)
| 21 | var _ huma.ErrorDetailer = (*huma.ErrorDetail)(nil) |
| 22 | |
| 23 | func TestError(t *testing.T) { |
| 24 | err := &huma.ErrorModel{ |
| 25 | Status: 400, |
| 26 | Detail: "test err", |
| 27 | } |
| 28 | |
| 29 | // Add some children. |
| 30 | err.Add(&huma.ErrorDetail{ |
| 31 | Message: "test detail", |
| 32 | Location: "body.foo", |
| 33 | Value: "bar", |
| 34 | }) |
| 35 | |
| 36 | err.Add(errors.New("plain error")) |
| 37 | |
| 38 | // Confirm errors were added. |
| 39 | assert.Equal(t, "test err", err.Error()) |
| 40 | assert.Len(t, err.Errors, 2) |
| 41 | assert.Equal(t, "test detail (body.foo: bar)", err.Errors[0].Error()) |
| 42 | assert.Equal(t, "plain error", err.Errors[1].Error()) |
| 43 | |
| 44 | // Ensure problem content types. |
| 45 | assert.Equal(t, "application/problem+json", err.ContentType("application/json")) |
| 46 | assert.Equal(t, "application/problem+cbor", err.ContentType("application/cbor")) |
| 47 | assert.Equal(t, "other", err.ContentType("other")) |
| 48 | } |
| 49 | |
| 50 | func TestErrorResponses(t *testing.T) { |
| 51 | // NotModified has a slightly different signature. |
nothing calls this directly
no test coverage detected
searching dependent graphs…