attest

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(substring string) containsMatcher

Contains creates a matcher that checks if actual contains the substring.

func GreaterThan added in v0.4.4

func GreaterThan[T cmp.Ordered](value T) greaterThanMatcher[T]

GreaterThan creates a matcher that asserts actual > value.

func HasLen

func HasLen[T any](length int) hasLenMatcher[T]

HasLen creates a matcher that validates the length of arrays, slices, maps, channels, or strings.

func Is

func Is[T comparable](value T) isMatcher[T]

Is creates a matcher that validates exact equality.

func IsNull

func IsNull[T any]() isNullMatcher[T]

IsNull creates a matcher that checks if a value is nil.

func LessThan added in v0.4.4

func LessThan[T cmp.Ordered](value T) lessThanMatcher[T]

LessThan creates a matcher that asserts actual < value.

func Matches

func Matches(pattern string) patternMatcher

Matches creates a matcher that checks if actual matches the regex pattern.

func NodeLogPath added in v0.4.14

func NodeLogPath(challengeKey, nodeName string) string

NodeLogPath returns the path to the log file for the given challenge and node.

func NodesWithLogs added in v0.4.18

func NodesWithLogs(challengeKey string) ([]string, error)

NodesWithLogs returns logical node names that have log files for the given challenge.

func Not

func Not[T any](matcher Matcher[T]) notMatcher[T]

Not creates a matcher that negates another matcher.

func OneOf

func OneOf[T comparable](values ...T) oneOfMatcher[T]

OneOf creates a matcher that accepts any of the provided values.

func RenderLogs added in v0.4.18

func RenderLogs(challengeKey string, nodeNames []string) error

RenderLogs reads log files for the given nodes and prints them interleaved by timestamp.

Types

type Check added in v0.4.7

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

Check describes an HTTP request and the conditions its response must satisfy.

func (*Check) Body added in v0.4.7

func (c *Check) Body(matchers ...Matcher[string]) *Check

Body adds expected HTTP response body matchers. All matchers must pass.

func (*Check) Consistently added in v0.4.7

func (c *Check) Consistently(timeout time.Duration) *Check

Consistently configures the assertion to verify success for the entire duration.

func (*Check) Eventually added in v0.4.7

func (c *Check) Eventually(timeout time.Duration) *Check

Eventually configures the assertion to retry until success or timeout.

func (*Check) Header added in v0.4.7

func (c *Check) Header(name string, matchers ...Matcher[string]) *Check

Header adds matchers for the named response header. All matchers must pass.

func (*Check) Hint added in v0.4.7

func (c *Check) Hint(help string) *Check

Hint sets the help text shown when the assertion fails.

func (*Check) JSON added in v0.4.7

func (c *Check) JSON(path string, matchers ...Matcher[string]) *Check

JSON adds expected matchers for a JSON field at the given gjson path. All matchers must pass.

func (*Check) Run added in v0.4.7

func (c *Check) Run()

Run executes the assertion and panics on failure.

func (*Check) Status added in v0.4.7

func (c *Check) Status(matchers ...Matcher[int]) *Check

Status adds expected HTTP response status code matchers. All matchers must pass.

type Do

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

Do provides the test harness and acts as the test runner.

func (*Do) AllNodes added in v0.4.4

func (do *Do) AllNodes(names ...string) NodeSelector

AllNodes returns a selector that passes when every node satisfies the assertion. If names are provided, only those nodes are checked.

func (*Do) AtLeastOneNode added in v0.4.4

func (do *Do) AtLeastOneNode(names ...string) NodeSelector

AtLeastOneNode returns a selector that passes when at least one node satisfies the assertion. If names are provided, only those nodes are checked.

func (*Do) Cancel

func (do *Do) Cancel()

func (*Do) Concurrently

func (do *Do) Concurrently(n int, fn func(i int))

Concurrently runs fn n times in parallel.

func (*Do) DELETE added in v0.4.0

func (do *Do) DELETE(sel NodeSelector, path string, args ...any) *Check

DELETE creates a Check for an HTTP DELETE request.

func (*Do) Done

func (do *Do) Done()

Done cancels the test context and stops all nodes. Containers are left in place so they can be inspected after a failure; they will be cleaned up at the start of the next run.

func (*Do) ExactlyOneNode added in v0.4.4

func (do *Do) ExactlyOneNode(names ...string) NodeSelector

ExactlyOneNode returns a selector that passes when exactly one node satisfies the assertion. If names are provided, only those nodes are checked.

func (*Do) ExceptNodes added in v0.4.19

func (do *Do) ExceptNodes(names ...string) NodeSelector

ExceptNodes returns a selector targeting all alive nodes except those specified.

func (*Do) Fetch added in v0.4.4

func (do *Do) Fetch(name, path string) *FetchResponse

Fetch makes a GET request to the named node and returns the raw response. Returns nil if the request fails (e.g. node is down).

func (*Do) GET added in v0.4.0

func (do *Do) GET(sel NodeSelector, path string, args ...any) *Check

GET creates a Check for an HTTP GET request.

func (*Do) Heal added in v0.4.1

func (do *Do) Heal()

Heal flushes all iptables rules on every node, restoring full connectivity.

func (*Do) Impair added in v0.4.19

func (do *Do) Impair(sel NodeSelector, impairments ...Impairment)

Impair applies network impairments to outgoing traffic on the selected nodes.

func (*Do) Kill

func (do *Do) Kill(name string)

Kill sends SIGKILL to the node immediately.

func (*Do) MockNode added in v0.4.0

func (do *Do) MockNode(name, port string)

func (*Do) Names added in v0.4.19

func (do *Do) Names(sel NodeSelector) []string

Names resolves a selector to the node names it targets.

func (*Do) Nodes added in v0.4.4

func (do *Do) Nodes() []string

Nodes returns the names of all alive nodes in the cluster.

func (*Do) PATCH added in v0.4.0

func (do *Do) PATCH(sel NodeSelector, path string, args ...any) *Check

PATCH creates a Check for an HTTP PATCH request.

func (*Do) POST added in v0.4.0

func (do *Do) POST(sel NodeSelector, path string, args ...any) *Check

POST creates a Check for an HTTP POST request.

func (*Do) PUT added in v0.4.0

func (do *Do) PUT(sel NodeSelector, path string, args ...any) *Check

PUT creates a Check for an HTTP PUT request.

func (*Do) Partition added in v0.4.1

func (do *Do) Partition(groups ...[]string)

Partition installs iptables DROP rules so nodes in different groups cannot reach each other. Rules are bidirectional.

func (*Do) Repair added in v0.4.19

func (do *Do) Repair(sel ...NodeSelector)

Repair removes tc netem impairments from the selected nodes. If no selector is given, all nodes are repaired.

func (*Do) Restart

func (do *Do) Restart(name string, sig ...syscall.Signal)

Restart restarts the node. Pass syscall.SIGKILL to crash immediately instead of graceful shutdown.

func (*Do) Settle added in v0.4.16

func (do *Do) Settle(d time.Duration)

Settle pauses for the given duration to let the cluster settle.

func (*Do) Start

func (do *Do) Start(name string)

Start starts a previously stopped or killed node.

func (*Do) Stop

func (do *Do) Stop(name string)

Stop sends SIGTERM to the node, then SIGKILL after the shutdown timeout.

type FetchResponse added in v0.4.4

type FetchResponse struct {
	Status int
	Body   []byte
}

FetchResponse is the result of a Fetch call.

func (*FetchResponse) JSON added in v0.4.4

func (r *FetchResponse) JSON(path string) string

JSON returns the string value at the given gjson path.

type H

type H map[string]string

H is a convenience type for HTTP headers.

type Impairment added in v0.4.19

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

Impairment describes a network condition applied to a node's outgoing traffic via tc netem.

func Delay added in v0.4.19

func Delay(d time.Duration, jitter ...time.Duration) Impairment

Delay adds a fixed latency to outgoing packets. An optional jitter value adds random variation: delay ± jitter.

func Duplicate added in v0.4.19

func Duplicate(pct float64) Impairment

Duplicate sends a percentage of outgoing packets twice.

func Loss added in v0.4.19

func Loss(pct float64) Impairment

Loss randomly drops a percentage of outgoing packets.

func Reorder added in v0.4.19

func Reorder(pct float64) Impairment

Reorder delivers a percentage of packets out of order. Must be combined with Delay. Without it, all packets go out immediately and no reordering occurs.

type JSONFieldMatcher added in v0.4.7

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

JSONFieldMatcher pairs a gjson path with a matcher for that field.

func JSON

func JSON(path string, matcher Matcher[string]) JSONFieldMatcher

JSON creates a matcher that extracts a JSON field at the given path and validates it.

func (JSONFieldMatcher) Check added in v0.4.7

func (m JSONFieldMatcher) Check(actual string) bool

func (JSONFieldMatcher) Expected added in v0.4.7

func (m JSONFieldMatcher) Expected() string

type Matcher added in v0.4.7

type Matcher[T any] interface {
	// Check returns true if actual satisfies this matcher's condition.
	Check(actual T) bool
	// Expected returns a human-readable description of what was expected.
	Expected() string
}

Matcher is a composable predicate used in assertions to validate actual values against expected conditions.

type NodeSelector added in v0.4.4

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

NodeSelector targets one or more nodes for an HTTP assertion.

func Node added in v0.4.0

func Node(name string) NodeSelector

Node returns a selector targeting a specific named node.

type Option added in v0.4.0

type Option func(*config)

Option configures a Suite.

func WithChallenge added in v0.4.5

func WithChallenge(key string) Option

WithChallenge sets the challenge key used to namespace Docker resources.

func WithCluster added in v0.4.0

func WithCluster(n int) Option

WithCluster declares N nodes named n1, n2, ... nN.

func WithClusterSettleDuration added in v0.4.16

func WithClusterSettleDuration(d time.Duration) Option

WithClusterSettleDuration sets how long Partition and Heal wait after topology changes for in-flight RPCs to drain and timeouts to expire.

func WithConcurrencyLimit added in v0.5.3

func WithConcurrencyLimit(n int) Option

WithConcurrencyLimit sets the maximum number of goroutines that Concurrently runs at once, and sizes the HTTP connection pool to match.

func WithNodeShutdownTimeout added in v0.4.0

func WithNodeShutdownTimeout(d time.Duration) Option

WithNodeShutdownTimeout sets how long to wait for a node to exit before sending SIGKILL.

func WithNodeStartupTimeout added in v0.5.2

func WithNodeStartupTimeout(d time.Duration) Option

WithNodeStartupTimeout sets how long to wait for a node to accept connections after starting.

func WithPollInterval added in v0.4.0

func WithPollInterval(d time.Duration) Option

WithPollInterval sets how often Eventually and Consistently poll.

func WithRequestTimeout added in v0.4.0

func WithRequestTimeout(d time.Duration) Option

WithRequestTimeout sets the HTTP client timeout per request.

type Suite

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

Suite represents a test suite with setup and test functions.

func New

func New(opts ...Option) *Suite

New creates a new test suite with optional configuration.

func (*Suite) Run

func (s *Suite) Run(ctx context.Context) bool

Run executes the test suite and returns results.

func (*Suite) Setup

func (s *Suite) Setup(fn func(*Do)) *Suite

Setup adds a setup function that runs before all tests.

func (*Suite) Test

func (s *Suite) Test(name string, fn func(*Do)) *Suite

Test adds a test case to the suite.

func (*Suite) With added in v0.4.0

func (s *Suite) With(opts ...Option) *Suite

With applies options to the suite configuration.

type TestFunc

type TestFunc struct {
	Name string
	Fn   func(*Do)
}

TestFunc represents a single test case with name and function.

Jump to

Keyboard shortcuts

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