
Web
Test HTTP Handlers in Go Without Starting a Real Server
Call handlers directly with httptest.NewRecorder and NewRequest, set path values by hand, fake the store behind them, and assert on status, headers and JSON.
9 min read
Tag
15 articles

Call handlers directly with httptest.NewRecorder and NewRequest, set path values by hand, fake the store behind them, and assert on status, headers and JSON.

Serve large files from Go with http.ServeContent so browsers can resume downloads and seek in video, and see exactly what each Range header gets back.

The zero value http.Client and http.Get have no timeout, lose connections when a body is not drained and read unlimited data. See each failure and its fix.