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

Function TestClientDisconnect

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

Source from the content-addressed store, hash-verified

3423}
3424
3425func TestClientDisconnect(t *testing.T) {
3426 _, api := humatest.New(t, huma.DefaultConfig("Test API", "1.0.0"))
3427
3428 huma.Get(api, "/error", func(ctx context.Context, i *struct{}) (*struct {
3429 Body string
3430 }, error) {
3431 return &struct{ Body string }{Body: "test"}, nil
3432 })
3433
3434 // Create and immediately cancel the context. This simulates a client
3435 // that has disconnected.
3436 ctx, cancel := context.WithCancel(context.Background())
3437 cancel()
3438 req, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/error", nil)
3439
3440 // Also make the response writer fail when writing.
3441 recorder := httptest.NewRecorder()
3442 resp := &BrokenWriter{recorder}
3443
3444 // We do not want any panics as this is not a real error.
3445 assert.NotPanics(t, func() {
3446 api.Adapter().ServeHTTP(resp, req)
3447 })
3448}
3449
3450type NestedResolversStruct struct {
3451 Field2 string `json:"field2"`

Callers

nothing calls this directly

Calls 4

NewFunction · 0.92
GetMethod · 0.65
ServeHTTPMethod · 0.65
AdapterMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…