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 ¶
- func Eventually(t *testing.T, ok func() bool)
- func NewTeeLogger(primary slog.Handler, collector *CollectingHandler) *slog.Logger
- type CollectingHandler
- func (h *CollectingHandler) Enabled(context.Context, slog.Level) bool
- func (h *CollectingHandler) FindMessage(msg string) []LogRecord
- func (h *CollectingHandler) Handle(_ context.Context, r slog.Record) error
- func (h *CollectingHandler) HasMessage(msg string) bool
- func (h *CollectingHandler) Logger() *slog.Logger
- func (h *CollectingHandler) Records() []LogRecord
- func (h *CollectingHandler) WaitForMessage(msg string, timeout time.Duration) bool
- func (h *CollectingHandler) WithAttrs([]slog.Attr) slog.Handler
- func (h *CollectingHandler) WithGroup(string) slog.Handler
- type JSONArrayCase
- type LogRecord
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Eventually ¶
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) 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.
type JSONArrayCase ¶
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.
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. |