Documentation
¶
Overview ¶
Package testutil provides utilities for running canary tests against the compiled Stripe CLI binary.
Index ¶
- Constants
- func CreateTempConfigDir(prefix string) (string, error)
- func GetAPIKey() string
- func HasAPIKey() bool
- func SanitizeOutput(s string) string
- type BackgroundProcess
- type Result
- type Runner
- func (r *Runner) Run(args ...string) (*Result, error)
- func (r *Runner) RunBackground(args ...string) (*BackgroundProcess, error)
- func (r *Runner) RunContext(ctx context.Context, args ...string) (*Result, error)
- func (r *Runner) WithConfigDir(dir string) *Runner
- func (r *Runner) WithEnv(env map[string]string) *Runner
- func (r *Runner) WithTimeout(timeout time.Duration) *Runner
- type RunnerOption
Constants ¶
const DefaultTimeout = 30 * time.Second
DefaultTimeout is the default timeout for command execution.
Variables ¶
This section is empty.
Functions ¶
func CreateTempConfigDir ¶
CreateTempConfigDir creates a temporary directory for isolated configuration. The caller is responsible for cleaning up the directory. This also creates the stripe subdirectory and an empty config.toml file so that config commands work properly.
func HasAPIKey ¶
func HasAPIKey() bool
HasAPIKey returns true if STRIPE_API_KEY is set in the environment.
func SanitizeOutput ¶
SanitizeOutput removes sensitive data from strings before logging. This helps prevent accidental secret exposure in CI logs.
Types ¶
type BackgroundProcess ¶
type BackgroundProcess struct {
// contains filtered or unexported fields
}
BackgroundProcess represents a running CLI command in the background.
func (*BackgroundProcess) GetOutput ¶
func (bp *BackgroundProcess) GetOutput() (stdout, stderr string)
GetOutput returns the current stdout and stderr contents.
func (*BackgroundProcess) Stop ¶
func (bp *BackgroundProcess) Stop() (*Result, error)
Stop kills the process and returns the final result.
func (*BackgroundProcess) WaitForOutput ¶
func (bp *BackgroundProcess) WaitForOutput(contains string, timeout time.Duration) error
WaitForOutput waits until combined output contains the expected string or timeout.
type Result ¶
type Result struct {
// Stdout is the standard output.
Stdout string
// Stderr is the standard error output.
Stderr string
// ExitCode is the process exit code.
ExitCode int
}
Result contains the output of a command execution.
func SanitizeResult ¶
SanitizeResult sanitizes both stdout and stderr of a Result.
type Runner ¶
type Runner struct {
// BinaryPath is the path to the stripe binary.
BinaryPath string
// ConfigDir is an isolated config directory for this test.
// If empty, a temp directory will be created.
ConfigDir string
// Env contains additional environment variables to set.
Env map[string]string
// Timeout is the command execution timeout.
// If zero, DefaultTimeout is used.
Timeout time.Duration
}
Runner executes the Stripe CLI binary with isolated configuration.
func NewRunner ¶
func NewRunner(opts ...RunnerOption) (*Runner, error)
NewRunner creates a new Runner with the binary path from STRIPE_CLI_BINARY env var. Options are applied after initializing defaults. Returns an error if the env var is not set or the binary doesn't exist.
func (*Runner) RunBackground ¶
func (r *Runner) RunBackground(args ...string) (*BackgroundProcess, error)
RunBackground starts the CLI in background and returns immediately. The returned BackgroundProcess can be used to wait for output, get current output, or stop the process.
func (*Runner) RunContext ¶
RunContext executes the stripe binary with the given context and arguments.
func (*Runner) WithConfigDir ¶
WithConfigDir creates a copy of the runner with an isolated config directory.
type RunnerOption ¶
type RunnerOption func(*Runner)
RunnerOption is a functional option for configuring a Runner at construction time.
func WithConfigDir ¶
func WithConfigDir(dir string) RunnerOption
WithConfigDir returns a RunnerOption that sets the config directory.
func WithEnv ¶
func WithEnv(env map[string]string) RunnerOption
WithEnv returns a RunnerOption that merges additional environment variables.
func WithTimeout ¶
func WithTimeout(timeout time.Duration) RunnerOption
WithTimeout returns a RunnerOption that sets the command execution timeout.