testhelp

package
v3.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2026 License: MIT Imports: 5 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 testhelp provides shared test utilities for the sockguard internal packages.

Package testhelp provides shared test utilities for the sockguard internal packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Eventually

func Eventually(t *testing.T, ok func() bool)

Eventually polls ok every 10 ms until it returns true or a 2-second deadline elapses. It calls t.Fatal if the condition is not met in time.

func NewTeeLogger

func NewTeeLogger(primary slog.Handler, collector *CollectingHandler) *slog.Logger

NewTeeLogger returns an *slog.Logger that writes to both primary (e.g. a slog.NewJSONHandler) and a CollectingHandler so tests can use both approaches.

Types

type CollectingHandler

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

CollectingHandler is an slog.Handler that captures structured records into memory so tests can assert on message, level, and attribute values without parsing text output.

func (*CollectingHandler) Enabled

Enabled always returns true so all levels are captured.

func (*CollectingHandler) FindMessage

func (h *CollectingHandler) FindMessage(msg string) []LogRecord

FindMessage returns all captured records whose Message field equals msg.

func (*CollectingHandler) Handle

Handle captures the record's message, level, and top-level attributes.

func (*CollectingHandler) HasMessage

func (h *CollectingHandler) HasMessage(msg string) bool

HasMessage reports whether any captured record has Message == msg.

func (*CollectingHandler) Logger

func (h *CollectingHandler) Logger() *slog.Logger

Logger returns a new *slog.Logger backed by this handler.

func (*CollectingHandler) Records

func (h *CollectingHandler) Records() []LogRecord

Records returns a snapshot of all captured records.

func (*CollectingHandler) WaitForMessage

func (h *CollectingHandler) WaitForMessage(msg string, timeout time.Duration) bool

WaitForMessage blocks until a record with Message == msg arrives or the deadline elapses. Returns true if the message was seen. Eliminates the sleep-poll-sleep pattern in tests that wait for asynchronous log output.

func (*CollectingHandler) WithAttrs

func (h *CollectingHandler) WithAttrs([]slog.Attr) slog.Handler

WithAttrs returns the same handler (attributes pre-attached to the logger are not needed for the assertion patterns used in these tests).

func (*CollectingHandler) WithGroup

func (h *CollectingHandler) WithGroup(string) slog.Handler

WithGroup returns the same handler.

type JSONArrayCase

type JSONArrayCase struct {
	Name   string
	Body   string
	Accept bool
}

JSONArrayCase is one upstream list body and the verdict every streaming JSON-array parser in this build has to reach on it.

Accept is true when the body is exactly one well-formed top-level JSON array, trailing whitespace included, and false when the parser must refuse it and let its caller answer 502. There is no third outcome: forwarding a body the parser could not account for in full is the failure these cases exist to catch, because the client reads the rewritten result as the complete list.

func JSONArrayTerminationCases

func JSONArrayTerminationCases() []JSONArrayCase

JSONArrayTerminationCases returns the shared table both list-body filters assert against: internal/visibility's patternFilterWriter.flushFiltered and internal/responsefilter's streamArrayResponse and decodeJSONObjectArray.

Two packages grew separate streaming decoders over the same Docker list bodies, and they drifted: responsefilter required the closing bracket and rejected trailing content, visibility did neither until the parsers were reconciled. Keeping one table means a case added for either package is a case the other has to answer too, instead of each package's own test file recording only the gaps someone happened to look for there.

Every body here starts with '[' or is empty, so it is meaningful on any route that walks an array. A non-array body like an object or a scalar is deliberately absent: responsefilter's libpod network-inspect route accepts a bare object on purpose, because Podman changed that response from a one-element array to a bare object at v3.1.0, so an object is a legitimate shape there and a refusal everywhere else. Each package covers that case in its own tests, where the route's expected shape is known.

type LogRecord

type LogRecord struct {
	Message string
	Level   slog.Level
	Attrs   map[string]any
}

LogRecord is a single captured slog record from a CollectingHandler.

Directories

Path Synopsis
Package podmanspec holds the test helpers that derive a Podman request-body field set from Podman's own Go source: fetch a file at a ref, parse its struct declarations with go/ast, and flatten the embedded structs the way encoding/json does.
Package podmanspec holds the test helpers that derive a Podman request-body field set from Podman's own Go source: fetch a file at a ref, parse its struct declarations with go/ast, and flatten the embedded structs the way encoding/json does.

Jump to

Keyboard shortcuts

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