Documentation
¶
Index ¶
- Constants
- func Contains(substring string) containsChecker
- func HasLen[T any](length int) hasLenChecker[T]
- func Is[T comparable](value T) isChecker[T]
- func IsNull[T any]() isNullChecker[T]
- func Matches(pattern string) matchesChecker
- func Not[T any](checker Checker[T]) notChecker[T]
- func OneOf[T comparable](values ...T) oneOfChecker[T]
- type Assert
- type AssertBase
- type CLIAssert
- type CLIPlan
- type Checker
- type Config
- type Do
- func (do *Do) Cancel()
- func (do *Do) Concurrently(fns ...func())
- func (do *Do) Done()
- func (do *Do) Exec(args ...string) *CLIPlan
- func (do *Do) HTTP(name, method, path string, args ...any) *HTTPPlan
- func (do *Do) Kill(name string)
- func (do *Do) MockProcess(name, realPort string)
- func (do *Do) Restart(name string, sig ...syscall.Signal)
- func (do *Do) Start(name string, args ...string)
- func (do *Do) Stop(name string)
- type H
- type HTTPAssert
- type HTTPPlan
- type JSONFieldChecker
- type Plan
- type PlanBase
- type Process
- type Suite
- type TestFunc
Constants ¶
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 ¶
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 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.
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 (*CLIPlan) Eventually ¶
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.
type Do ¶
type Do struct {
// contains filtered or unexported fields
}
Do provides the test harness and acts as the test runner.
func (*Do) Concurrently ¶
func (do *Do) Concurrently(fns ...func())
Concurrently runs multiple functions in parallel and waits for completion.
func (*Do) MockProcess ¶
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 (*HTTPPlan) Eventually ¶
func (*HTTPPlan) T ¶
func (p *HTTPPlan) T() *HTTPAssert
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 (*Suite) WithConfig ¶
WithConfig sets the configuration for the test suite.