attest

package
v0.4.11 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 22 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 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.

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()

Cancel cancels the Do context, stopping all in-flight assertions.

func (*Do) Concurrently

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

Concurrently runs fn n times in parallel, passing each invocation a 1-based index.

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) 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) 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)

MockNode registers a pre-running server as a node. Used in tests.

func (*Do) Nodes added in v0.4.4

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

Nodes returns the names of all 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. Call Heal to restore connectivity.

func (*Do) Restart

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

Restart stops the node and starts it again. Pass syscall.SIGKILL to crash immediately instead of graceful shutdown.

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 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 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 WithNodeStartTimeout added in v0.4.0

func WithNodeStartTimeout(d time.Duration) Option

WithNodeStartTimeout 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.

func WithRetryTimeout added in v0.4.7

func WithRetryTimeout(d time.Duration) Option

WithRetryTimeout sets the default timeout for Eventually and Consistently.

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