Documentation
¶
Overview ¶
Package testutil holds helpers shared by tests across packages.
Index ¶
- Constants
- func CaptureOutput(t *testing.T, fn func()) (stdout string, stderr string)
- func CaptureStdout(t *testing.T, fn func()) string
- func NewNoRequestServer(t *testing.T) *httptest.Server
- func StubClient(fn func(*http.Request) (status int, body string)) *http.Client
- type PollRecorder
- type StubTransport
Constants ¶
const StubBaseURL = "http://stub.invalid"
StubBaseURL is the BaseURL to pin on a client whose transport is stubbed: it must parse, and it must never resolve.
Variables ¶
This section is empty.
Functions ¶
func CaptureOutput ¶
CaptureOutput returns what fn writes to os.Stdout and os.Stderr.
func CaptureStdout ¶
CaptureStdout returns what fn writes to os.Stdout.
func NewNoRequestServer ¶ added in v1.16.0
NewNoRequestServer returns a server that fails the test on any request, for asserting a call was refused before anything was sent.
Types ¶
type PollRecorder ¶ added in v1.12.0
type PollRecorder struct {
// contains filtered or unexported fields
}
PollRecorder collects the time of each poll a stubbed server sees, so a test can assert the schedule that produced them rather than the poll count alone. A count is a weak witness: a widened schedule and a fixed tick can land on the same number. Under testing/synctest the times come off the bubble's fake clock, which makes the gaps exact.
func (*PollRecorder) Record ¶ added in v1.12.0
func (r *PollRecorder) Record()
Record marks one poll as having arrived now. Safe to call from a handler goroutine.
func (*PollRecorder) WidestGap ¶ added in v1.12.0
func (r *PollRecorder) WidestGap() time.Duration
WidestGap returns the longest interval between consecutive polls, or 0 when fewer than two arrived. Only a schedule that widens with age can produce a gap above its own base tick.
type StubTransport ¶ added in v1.12.0
StubTransport answers every request from fn, with no socket and no server goroutine. A poll loop under testing/synctest needs that: the fake clock only advances while every goroutine in the bubble is durably blocked, and a real network read never counts as durably blocked.