MCPcopy
hub / github.com/danielgtaylor/huma / TestError

Function TestError

error_test.go:23–48  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21var _ huma.ErrorDetailer = (*huma.ErrorDetail)(nil)
22
23func 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
50func TestErrorResponses(t *testing.T) {
51 // NotModified has a slightly different signature.

Callers

nothing calls this directly

Calls 5

AddMethod · 0.95
ErrorMethod · 0.95
ContentTypeMethod · 0.95
LenMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…