attest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TimingImmediate timing = iota
	TimingEventually
	TimingConsistently
)

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 Assert

type Assert interface {
	// Assert executes the test plan and validates the result.
	Assert(help string)
	// contains filtered or unexported methods
}

Assert defines the interface for executing and validating test assertions.

type AssertBase

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

AssertBase provides common assertion functionality.

type CLIAssert

type CLIAssert struct {
	AssertBase
	// contains filtered or unexported fields
}

CLIAssert provides CLI command output and exit code assertions.

func (*CLIAssert) Assert

func (a *CLIAssert) Assert(help string)

func (*CLIAssert) ExitCode

func (a *CLIAssert) ExitCode(checkers ...Checker[int]) *CLIAssert

ExitCode adds expected exit code checkers. All checkers must pass.

func (*CLIAssert) Output

func (a *CLIAssert) Output(checkers ...Checker[string]) *CLIAssert

Output adds expected command output checkers. All checkers must pass.

type CLIPlan

type CLIPlan struct {
	PlanBase
	// contains filtered or unexported fields
}

CLIPlan represents a test plan for a CLI command execution.

func (*CLIPlan) Consistently

func (p *CLIPlan) Consistently() *CLIPlan

func (*CLIPlan) Eventually

func (p *CLIPlan) Eventually() *CLIPlan

func (*CLIPlan) For

func (p *CLIPlan) For(timeout time.Duration) *CLIPlan

func (*CLIPlan) T

func (p *CLIPlan) T() *CLIAssert

func (*CLIPlan) Within

func (p *CLIPlan) Within(timeout time.Duration) *CLIPlan

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 Config

type Config struct {
	// Command is the script/command used to build & run the system under test.
	Command string

	// WorkingDir is the base directory for test runs.
	WorkingDir string

	// ProcessStartTimeout for process startup.
	ProcessStartTimeout time.Duration
	// ProcessShutdownTimeout for process shutdown.
	ProcessShutdownTimeout time.Duration
	// ProcessRestartDelay between stop and start during restart.
	ProcessRestartDelay time.Duration

	// DefaultRetryTimeout for Eventually and Consistently operations.
	DefaultRetryTimeout time.Duration
	// RetryPollInterval for Eventually and Consistently operations.
	RetryPollInterval time.Duration

	// ExecuteTimeout for HTTP client requests.
	ExecuteTimeout time.Duration
}

Config holds configuration options for the test framework.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default configuration.

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

func (*Do) Concurrently

func (do *Do) Concurrently(fns ...func())

Concurrently runs multiple functions in parallel and waits for completion.

func (*Do) Done

func (do *Do) Done()

Done cleans up all running processes.

func (*Do) Exec

func (do *Do) Exec(args ...string) *CLIPlan

Exec creates a test plan for a CLI command execution.

func (*Do) HTTP

func (do *Do) HTTP(name, method, path string, args ...any) *HTTPPlan

HTTP creates a test plan for an HTTP request.

func (*Do) Kill

func (do *Do) Kill(name string)

Kill sends SIGKILL to kill the process immediately.

func (*Do) MockProcess

func (do *Do) MockProcess(name, realPort string)

func (*Do) Restart

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

Restart stops the process and starts it again.

func (*Do) Start

func (do *Do) Start(name string, args ...string)

Start starts the process with an OS-assigned port.

func (*Do) Stop

func (do *Do) Stop(name string)

Stop sends SIGTERM to the process, then SIGKILL after timeout.

type H

type H map[string]string

H is a convenience type for HTTP headers.

type HTTPAssert

type HTTPAssert struct {
	AssertBase
	// contains filtered or unexported fields
}

HTTPAssert provides assertions for HTTP response validation.

func (*HTTPAssert) Assert

func (a *HTTPAssert) Assert(help string)

func (*HTTPAssert) Body

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

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

func (*HTTPAssert) JSON

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

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

func (*HTTPAssert) Status

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

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

type HTTPPlan

type HTTPPlan struct {
	PlanBase
	// contains filtered or unexported fields
}

HTTPPlan represents a test plan for an HTTP request.

func (*HTTPPlan) Consistently

func (p *HTTPPlan) Consistently() *HTTPPlan

func (*HTTPPlan) Eventually

func (p *HTTPPlan) Eventually() *HTTPPlan

func (*HTTPPlan) For

func (p *HTTPPlan) For(timeout time.Duration) *HTTPPlan

func (*HTTPPlan) T

func (p *HTTPPlan) T() *HTTPAssert

func (*HTTPPlan) Within

func (p *HTTPPlan) Within(timeout time.Duration) *HTTPPlan

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 Plan

type Plan[P any, A any] interface {
	// Eventually configures the plan to retry until success or timeout.
	Eventually() P
	// Within sets a custom timeout for Eventually.
	Within(time.Duration) P
	// Consistently configures the plan to verify success for the entire duration.
	Consistently() P
	// For sets a custom timeout for Consistently.
	For(time.Duration) P
	// T returns the test for this plan.
	T() A
}

Plan represents a test plan to be asserted.

type PlanBase

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

PlanBase provides common plan functionality.

type Process

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

Process represents a running process.

type Suite

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

Suite represents a test suite with setup and test functions.

func New

func New() *Suite

New creates a new empty test suite.

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

func (s *Suite) WithConfig(config *Config) *Suite

WithConfig sets the configuration for the test suite.

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