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

Interface TestAPI

humatest/humatest.go:42–188  ·  view source on GitHub ↗

TestAPI is a `huma.API` with additional methods specifically for testing.

Source from the content-addressed store, hash-verified

40
41// TestAPI is a `huma.API` with additional methods specifically for testing.
42type TestAPI interface {
43 huma.API
44
45 // DoCtx a request against the API with a custom [context.Context] in the
46 // [http.Request]. Args, if provided, should be string headers like
47 // `Content-Type: application/json`, an `io.Reader` for the request body, or a
48 // slice/map/struct which will be serialized to JSON and sent as the request
49 // body. Anything else will panic.
50 DoCtx(ctx context.Context, method, path string, args ...any) *httptest.ResponseRecorder
51
52 // Do a request against the API using [context.Background] in the [http.Request].
53 // Args, if provided, should be string headers like `Content-Type:
54 // application/json`, an `io.Reader` for the request body, or a slice/map/struct
55 // which will be serialized to JSON and sent as the request body. Anything else
56 // will panic.
57 Do(method, path string, args ...any) *httptest.ResponseRecorder
58
59 // GetCtx performs a GET request against the API with a custom [context.Context]
60 // in the [http.Request]. Args, if provided, should be string headers like
61 // `Content-Type: application/json`, an `io.Reader` for the request body, or a
62 // slice/map/struct which will be serialized to JSON and sent as the request
63 // body. Anything else will panic.
64 //
65 // // Make a GET request
66 // api.GetCtx(ctx, "/foo")
67 //
68 // // Make a GET request with a custom header.
69 // api.GetCtx(ctx, "/foo", "X-My-Header: my-value")
70 GetCtx(ctx context.Context, path string, args ...any) *httptest.ResponseRecorder
71
72 // Get performs a GET request against the API using [context.Background] in the
73 // [http.Request]. Args, if provided, should be string headers like
74 // `Content-Type: application/json`, an `io.Reader` for the request body, or a
75 // slice/map/struct which will be serialized to JSON and sent as the request
76 // body. Anything else will panic.
77 //
78 // // Make a GET request
79 // api.Get("/foo")
80 //
81 // // Make a GET request with a custom header.
82 // api.Get("/foo", "X-My-Header: my-value")
83 Get(path string, args ...any) *httptest.ResponseRecorder
84
85 // PostCtx performs a POST request against the API with a custom
86 // [context.Context] in the [http.Request]. Args, if provided, should be string
87 // headers like `Content-Type: application/json`, an `io.Reader` for the request
88 // body, or a slice/map/struct which will be serialized to JSON and sent as the
89 // request body. Anything else will panic.
90 //
91 // // Make a POST request
92 // api.PostCtx(ctx, "/foo", strings.NewReader(`{"foo": "bar"}`))
93 //
94 // // Make a POST request with a custom header.
95 // api.PostCtx(ctx, "/foo", "X-My-Header: my-value", MyBody{Foo: "bar"})
96 PostCtx(ctx context.Context, path string, args ...any) *httptest.ResponseRecorder
97
98 // Post performs a POST request against the API using [context.Background] in the
99 // [http.Request]. Args, if provided, should be string headers like

Callers 35

testAdapterFunction · 0.65
TestHumaFiberV2Function · 0.65
CallPingFunction · 0.65
TestHumaFiberFunction · 0.65
TestCustomMiddlewareFunction · 0.65
boolTagFunction · 0.65
intTagFunction · 0.65
floatTagFunction · 0.65
stringTagFunction · 0.65
jsonTagFunction · 0.65
SchemaFromFieldFunction · 0.65

Implementers 1

testAPIhumatest/humatest.go

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…