Documentation
¶
Index ¶
- func Contains(substring string) containsChecker
- func GreaterThan[T cmp.Ordered](value T) greaterThanChecker[T]
- func HasLen[T any](length int) hasLenChecker[T]
- func Is[T comparable](value T) isChecker[T]
- func IsNull[T any]() isNullChecker[T]
- func LessThan[T cmp.Ordered](value T) lessThanChecker[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) Header(name string, checkers ...Checker[string]) *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) AllNodes(names ...string) NodeSelector
- func (do *Do) AtLeastOneNode(names ...string) NodeSelector
- func (do *Do) Cancel()
- func (do *Do) Concurrently(n int, fn func(i int))
- func (do *Do) DELETE(sel NodeSelector, path string, args ...any) *Assertion
- func (do *Do) Done()
- func (do *Do) ExactlyOneNode(names ...string) NodeSelector
- func (do *Do) Fetch(name, path string) *FetchResponse
- func (do *Do) GET(sel NodeSelector, 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) Nodes() []string
- func (do *Do) PATCH(sel NodeSelector, path string, args ...any) *Assertion
- func (do *Do) POST(sel NodeSelector, path string, args ...any) *Assertion
- func (do *Do) PUT(sel NodeSelector, 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 FetchResponse
- type H
- type JSONFieldChecker
- type NodeSelector
- type Option
- func WithAssertTimeout(d time.Duration) Option
- func WithChallenge(key string) Option
- func WithCluster(n int) Option
- func WithNodeShutdownTimeout(d time.Duration) Option
- func WithNodeStartTimeout(d time.Duration) Option
- func WithPollInterval(d time.Duration) Option
- func WithRequestTimeout(d time.Duration) 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 GreaterThan ¶ added in v0.4.4
GreaterThan creates a checker that asserts actual > value.
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.
func (*Assertion) Header ¶ added in v0.4.4
Header adds checkers for the named response header. 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) 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 ¶
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) *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) 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) *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) MockNode ¶ added in v0.4.0
MockNode registers a pre-running server as a node. Used in tests.
func (*Do) PATCH ¶ added in v0.4.0
func (do *Do) PATCH(sel NodeSelector, 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(sel NodeSelector, 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(sel NodeSelector, path string, args ...any) *Assertion
PUT creates an assertion for an HTTP PUT request.
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 FetchResponse ¶ added in v0.4.4
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 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 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 WithAssertTimeout ¶ added in v0.4.0
WithAssertTimeout sets the default timeout for Eventually and Consistently.
func WithChallenge ¶ added in v0.4.5
WithChallenge sets the challenge key used to namespace Docker resources.
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.