attest

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(substring string) containsChecker

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

func HasLen

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

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

func Is

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

Is creates a checker that validates exact equality.

func IsNull

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

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

func Matches

func Matches(pattern string) matchesChecker

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

func Not

func Not[T any](checker Checker[T]) notChecker[T]

Not creates a checker that negates another checker.

func OneOf

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

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

Types

type Assertion added in v0.4.0

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

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

func (*Assertion) Body added in v0.4.0

func (a *Assertion) Body(checkers ...Checker[string]) *Assertion

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

func (*Assertion) Check added in v0.4.0

func (a *Assertion) Check()

Check executes the assertion and panics on failure.

func (*Assertion) Consistently added in v0.4.0

func (a *Assertion) Consistently(timeout ...time.Duration) *Assertion

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

func (*Assertion) Eventually added in v0.4.0

func (a *Assertion) Eventually(timeout ...time.Duration) *Assertion

Eventually configures the assertion to retry until success or timeout.

func (*Assertion) Hint added in v0.4.0

func (a *Assertion) Hint(help string) *Assertion

Hint sets the help text shown when the assertion fails.

func (*Assertion) JSON added in v0.4.0

func (a *Assertion) JSON(path string, checkers ...Checker[string]) *Assertion

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

func (*Assertion) Status added in v0.4.0

func (a *Assertion) Status(checkers ...Checker[int]) *Assertion

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

type Checker

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

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

type Do

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

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

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(name, path string, args ...any) *Assertion

DELETE creates an assertion 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) GET added in v0.4.0

func (do *Do) GET(name, path string, args ...any) *Assertion

GET creates an assertion 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) PATCH added in v0.4.0

func (do *Do) PATCH(name, path string, args ...any) *Assertion

PATCH creates an assertion for an HTTP PATCH request.

func (*Do) POST added in v0.4.0

func (do *Do) POST(name, path string, args ...any) *Assertion

POST creates an assertion for an HTTP POST request.

func (*Do) PUT added in v0.4.0

func (do *Do) PUT(name, path string, args ...any) *Assertion

PUT creates an assertion 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 H

type H map[string]string

H is a convenience type for HTTP headers.

type JSONFieldChecker

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

JSONFieldChecker pairs a gjson path with a checker for that field.

func JSON

func JSON(path string, checker Checker[string]) JSONFieldChecker

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

func (JSONFieldChecker) Check

func (m JSONFieldChecker) Check(actual string) bool

func (JSONFieldChecker) Expected

func (m JSONFieldChecker) Expected() string

type Node added in v0.4.0

type Node interface {
	ContainerIP() string
	MappedPort() int

	Start(ctx context.Context) error
	Stop(ctx context.Context, timeout time.Duration) error
	Kill(ctx context.Context) error
	Exec(ctx context.Context, args ...string) error
}

Node is the interface satisfied by containerNode and mockNode.

type Option added in v0.4.0

type Option func(*config)

Option configures a Suite.

func WithAssertTimeout added in v0.4.0

func WithAssertTimeout(d time.Duration) Option

WithAssertTimeout sets the default timeout for Eventually and Consistently.

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.

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