testrec

package
v0.1.0-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testrec records what a test HTTP fixture was asked for, safely.

net/http serves each connection on its own goroutine, and this scanner probes with bounded concurrency by design, so a fixture that records requests into a captured slice is racing whenever the stage under test does its job. That is not hypothetical: the first eval for Neon table enumeration appended to a bare slice, passed under `go test`, and failed under `go test -race` — but only because the scheduler happened to overlap two appends on that run. A racy recorder that gets lucky reports nothing and silently drops entries, so the assertions built on it end up describing evidence that was never collected.

Log is deliberately a log rather than a counter or a flag. A bool says that something happened; a log says what happened, which is the difference between a test that can only confirm its own expectation and one that can show you the request it objected to when it fails.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Log

type Log struct {
	// contains filtered or unexported fields
}

Log is a concurrency-safe record of fixture observations. The zero value is ready to use, so a fixture declares `var asked testrec.Log` and is correct.

func (*Log) Add

func (l *Log) Add(s string)

Add records one observation.

func (*Log) Count

func (l *Log) Count(sub string) int

Count returns how many observations contain sub.

func (*Log) Entries

func (l *Log) Entries() []string

Entries returns a copy, in the order observed. A copy because the caller is usually a test assertion running while the server may still be handling a request, and handing out the live slice would reintroduce the race this package exists to remove.

func (*Log) Has

func (l *Log) Has(sub string) bool

Has reports whether any observation contains sub.

func (*Log) Last

func (l *Log) Last() string

Last is the most recent observation, or "" if there is none.

func (*Log) Len

func (l *Log) Len() int

Len is the number of observations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL