testutil

package
v1.40.2 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package testutil provides utilities for running canary tests against the compiled Stripe CLI binary.

Index

Constants

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout is the default timeout for command execution.

Variables

This section is empty.

Functions

func CreateTempConfigDir

func CreateTempConfigDir(prefix string) (string, error)

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 GetAPIKey

func GetAPIKey() string

GetAPIKey returns the STRIPE_API_KEY from the environment.

func HasAPIKey

func HasAPIKey() bool

HasAPIKey returns true if STRIPE_API_KEY is set in the environment.

func SanitizeOutput

func SanitizeOutput(s string) string

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

func SanitizeResult(r *Result) *Result

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

func (r *Runner) Run(args ...string) (*Result, error)

Run executes the stripe binary with the given arguments.

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

func (r *Runner) RunContext(ctx context.Context, args ...string) (*Result, error)

RunContext executes the stripe binary with the given context and arguments.

func (*Runner) WithConfigDir

func (r *Runner) WithConfigDir(dir string) *Runner

WithConfigDir creates a copy of the runner with an isolated config directory.

func (*Runner) WithEnv

func (r *Runner) WithEnv(env map[string]string) *Runner

WithEnv creates a copy of the runner with additional environment variables.

func (*Runner) WithTimeout

func (r *Runner) WithTimeout(timeout time.Duration) *Runner

WithTimeout creates a copy of the runner with a different timeout.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL