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

Function TestContextValue

api_test.go:72–90  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

70}
71
72func TestContextValue(t *testing.T) {
73 _, api := humatest.New(t)
74
75 api.UseMiddleware(func(ctx huma.Context, next func(huma.Context)) {
76 // Make an updated context available to the handler.
77 ctx = huma.WithValue(ctx, "foo", "bar")
78 next(ctx)
79 assert.Equal(t, http.StatusNoContent, ctx.Status())
80 })
81
82 // Register a simple hello world operation in the API.
83 huma.Get(api, "/test", func(ctx context.Context, input *struct{}) (*struct{}, error) {
84 assert.Equal(t, "bar", ctx.Value("foo"))
85 return nil, nil
86 })
87
88 resp := api.Get("/test")
89 assert.Equal(t, http.StatusNoContent, resp.Code)
90}
91
92func TestResponseContentTypeWithExtensions(t *testing.T) {
93 _, api := humatest.New(t)

Callers

nothing calls this directly

Calls 5

NewFunction · 0.92
UseMiddlewareMethod · 0.65
StatusMethod · 0.65
GetMethod · 0.65
ValueMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…