Documentation
¶
Index ¶
- 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 Assertion
- func (a *Assertion) Body(checkers ...Checker[string]) *Assertion
- func (a *Assertion) Check()
- func (a *Assertion) Consistently(timeout ...time.Duration) *Assertion
- func (a *Assertion) Eventually(timeout ...time.Duration) *Assertion
- func (a *Assertion) Hint(help string) *Assertion
- func (a *Assertion) JSON(path string, checkers ...Checker[string]) *Assertion
- func (a *Assertion) Status(checkers ...Checker[int]) *Assertion
- type Checker
- type Do
- func (do *Do) Cancel()
- func (do *Do) Concurrently(n int, fn func(i int))
- func (do *Do) DELETE(name, path string, args ...any) *Assertion
- func (do *Do) Done()
- func (do *Do) GET(name, path string, args ...any) *Assertion
- func (do *Do) Heal()
- func (do *Do) Kill(name string)
- func (do *Do) MockNode(name, port string)
- func (do *Do) PATCH(name, path string, args ...any) *Assertion
- func (do *Do) POST(name, path string, args ...any) *Assertion
- func (do *Do) PUT(name, path string, args ...any) *Assertion
- func (do *Do) Partition(groups ...[]string)
- func (do *Do) Restart(name string, sig ...syscall.Signal)
- func (do *Do) Start(name string)
- func (do *Do) Stop(name string)
- type H
- type JSONFieldChecker
- type Node
- type Option
- type Suite
- type TestFunc
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 ¶
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 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
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
Consistently configures the assertion to verify success for the entire duration.
func (*Assertion) Eventually ¶ added in v0.4.0
Eventually configures the assertion to retry until success or timeout.
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 ¶
Concurrently runs fn n times in parallel, passing each invocation a 1-based index.
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) Heal ¶ added in v0.4.1
func (do *Do) Heal()
Heal flushes all iptables rules on every node, restoring full connectivity.
func (*Do) MockNode ¶ added in v0.4.0
MockNode registers a pre-running server as a node. Used in tests.
func (*Do) Partition ¶ added in v0.4.1
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 ¶
Restart stops the node and starts it again. Pass syscall.SIGKILL to crash immediately instead of graceful shutdown.
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
WithAssertTimeout sets the default timeout for Eventually and Consistently.
func WithCluster ¶ added in v0.4.0
WithCluster declares N nodes named n1, n2, ... nN.
func WithNodeShutdownTimeout ¶ added in v0.4.0
WithNodeShutdownTimeout sets how long to wait for a node to exit before sending SIGKILL.
func WithNodeStartTimeout ¶ added in v0.4.0
WithNodeStartTimeout sets how long to wait for a node to accept connections after starting.
func WithPollInterval ¶ added in v0.4.0
WithPollInterval sets how often Eventually and Consistently poll.
func WithRequestTimeout ¶ added in v0.4.0
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.