fixtures

package
v0.0.0-...-63e4bc9 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 13 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 fixtures holds the servers, handlers and requests that the test suites share. It imports ehttp, so it lives apart from ehttptest, which the tests inside package ehttp import.

Index

Constants

View Source
const (
	OriginA    = "https://app.example"
	OriginB    = "https://admin.example"
	OriginEvil = "https://evil.example"
)

Origins used by the CORS suites.

Variables

This section is empty.

Functions

func CaptureLogs

func CaptureLogs(t *testing.T) *observer.ObservedLogs

CaptureLogs swaps the global zap logger. Tests that call it are serial.

func Client

func Client() *http.Client

Client returns a client that keeps raw responses: no redirects, no transparent gzip, short overall deadline.

func CorsServer

func CorsServer(_ testing.TB, opts *ehttp.CorsOptions) *ehttp.Server

CorsServer builds a server with the Cors middleware. Nil options mean DefaultCorsOptions.

func Fetch

func Fetch(t testing.TB, method, url string, hdr http.Header) (resp *http.Response, body string)

Fetch sends one request and returns the response and its whole body.

func FreePort

func FreePort(t testing.TB) string

FreePort reserves and releases a loopback port.

func Handler

Handler builds a server that serves h on GET /x (and HEAD) with the given route middlewares, in order (first = outermost). It registers one method only: GET plus POST on the same path answers 405 for POST.

func HandlerLogged

func HandlerLogged(l *zap.Logger, h ehttp.HandlerFunc, mws ...ehttp.MiddlewareHandlerFunc) http.Handler

HandlerLogged is Handler with the server logger set.

func OK

func OK(res *ehttp.ResponseWriter, _ *ehttp.Request)

OK answers 200 with the body "ok".

func ObservedLogger

func ObservedLogger() (*zap.Logger, *observer.ObservedLogs)

ObservedLogger returns a logger that records its entries, for WithLogger. It does not touch the global logger, so the test can run in parallel.

func PostHandler

PostHandler is Handler for POST /x.

func Raw

func Raw(t testing.TB, addr, raw string) string

Raw writes raw bytes to addr and returns everything the server sends until it closes the connection or 2s pass.

func Req

func Req(method, target string, kv ...string) *http.Request

Req builds an in-memory request with headers given as key, value pairs.

func Start

func Start(t testing.TB, srv *ehttp.Server) *httptest.Server

Start serves srv through a real net/http server.

func Status

func Status(code int, body string) ehttp.HandlerFunc

Status answers with code and body.

Types

type Listening

type Listening struct {
	Port   string
	Cancel context.CancelFunc
	Result chan error
}

Listening is a server started by Listen.

func Listen

func Listen(t testing.TB, mk func(port string) *ehttp.Server) *Listening

Listen starts srv.Listen on a free port and waits until it accepts.

Jump to

Keyboard shortcuts

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