| 3423 | } |
| 3424 | |
| 3425 | func 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 | |
| 3450 | type NestedResolversStruct struct { |
| 3451 | Field2 string `json:"field2"` |