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

Function TestResolverWithPointer

huma_test.go:3554–3574  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3552}
3553
3554func TestResolverWithPointer(t *testing.T) {
3555 // Allow using pointers in input structs if they are not path/query/header/cookie parameters
3556 r, app := humatest.New(t, huma.DefaultConfig("Test API", "1.0.0"))
3557 huma.Register(app, huma.Operation{
3558 OperationID: "test",
3559 Method: http.MethodPut,
3560 Path: "/test",
3561 }, func(ctx context.Context, input *struct {
3562 ResolverWithPointer
3563 }) (*struct{}, error) {
3564 // Exactly one call should have been made to the resolver.
3565 assert.Equal(t, "String", *input.Ptr)
3566 return nil, nil
3567 })
3568
3569 req, _ := http.NewRequest(http.MethodPut, "/test", strings.NewReader(`{}`))
3570 req.Header.Set("Content-Type", "application/json")
3571 w := httptest.NewRecorder()
3572 r.ServeHTTP(w, req)
3573 assert.Equal(t, http.StatusNoContent, w.Code, w.Body.String())
3574}
3575
3576func TestParamPointerPanics(t *testing.T) {
3577 // For now, we don't support these, so we panic rather than have subtle

Callers

nothing calls this directly

Calls 3

NewFunction · 0.92
ServeHTTPMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…