Documentation
¶
Overview ¶
Package scenario provides a high-level test scenario that combines a Scene, an Engine, and a runtime Context to provide a terse API for integration tests.
Index ¶
- Variables
- func SetGlobalInProcessRunner(runner InProcessRunner)
- type InProcessRunner
- type Scenario
- func (s *Scenario) Checkout(branch string) *Scenario
- func (s *Scenario) CheckoutQuiet(branch string) *Scenario
- func (s *Scenario) Commit(message string) *Scenario
- func (s *Scenario) CommitChange(name, message string) *Scenario
- func (s *Scenario) CreateBranch(name string) *Scenario
- func (s *Scenario) CreateBranchQuiet(name string) *Scenario
- func (s *Scenario) ExpectBranch(expected string) *Scenario
- func (s *Scenario) ExpectBranchFixed(branch string) *Scenario
- func (s *Scenario) ExpectBranchNotFixed(branch string) *Scenario
- func (s *Scenario) ExpectStackStructure(expected map[string]string) *Scenario
- func (s *Scenario) Log(args ...any)
- func (s *Scenario) Logf(format string, args ...any)
- func (s *Scenario) Rebuild() *Scenario
- func (s *Scenario) Run(args ...string) *Scenario
- func (s *Scenario) RunCli(args ...string) *Scenario
- func (s *Scenario) RunCliAndGetOutput(args ...string) (string, error)
- func (s *Scenario) RunExpectError(args ...string) *Scenario
- func (s *Scenario) RunGit(args ...string) *Scenario
- func (s *Scenario) TrackBranch(branch, parent string) *Scenario
- func (s *Scenario) WithBinaryPath(path string) *Scenario
- func (s *Scenario) WithDiamondStack() *Scenario
- func (s *Scenario) WithInProcess(inProcess bool) *Scenario
- func (s *Scenario) WithInitialCommit() *Scenario
- func (s *Scenario) WithLinearStack(names ...string) *Scenario
- func (s *Scenario) WithLinearStack3() *Scenario
- func (s *Scenario) WithStack(structure map[string]string) *Scenario
- func (s *Scenario) WithUncommittedChange(name string) *Scenario
Constants ¶
This section is empty.
Variables ¶
var GlobalInProcessRunner = &struct { Get func() InProcessRunner Set func(InProcessRunner) }{ Get: GetGlobalInProcessRunner, Set: SetGlobalInProcessRunner, }
GlobalInProcessRunner is kept for backward compatibility. It's a pointer to a struct that provides thread-safe access. Use SetGlobalInProcessRunner and GetGlobalInProcessRunner directly for better clarity.
Functions ¶
func SetGlobalInProcessRunner ¶
func SetGlobalInProcessRunner(runner InProcessRunner)
SetGlobalInProcessRunner sets the global in-process runner in a thread-safe way.
Types ¶
type InProcessRunner ¶
InProcessRunner is a function that executes a stackit command in-process.
func GetGlobalInProcessRunner ¶
func GetGlobalInProcessRunner() InProcessRunner
GetGlobalInProcessRunner gets the global in-process runner in a thread-safe way.
type Scenario ¶
type Scenario struct {
T *testing.T
Scene *testhelpers.Scene
Engine engine.Engine
Context *app.Context
BinaryPath string
InProcess bool
Output *bytes.Buffer
}
Scenario represents a high-level test scenario that combines a Scene, an Engine, and a runtime Context to provide a terse API for integration tests.
func NewRemoteScenario ¶
NewRemoteScenario creates a new Scenario backed by a cached scene that already has a local bare "origin" remote and trunk pushed there.
func NewScenario ¶
func NewScenario(t *testing.T, setup testhelpers.SceneSetup) *Scenario
NewScenario creates a new Scenario with an optional setup function. It is safe for parallel tests as it uses NewSceneParallel.
func NewScenarioParallel ¶
func NewScenarioParallel(t *testing.T, setup testhelpers.SceneSetup) *Scenario
NewScenarioParallel creates a new Scenario that is safe for parallel tests. It does NOT set global environment variables or initialize the Go Engine/Context. Use this for tests that primarily call the CLI binary.
func (*Scenario) CheckoutQuiet ¶
CheckoutQuiet checks out a branch without rebuilding the engine.
func (*Scenario) CommitChange ¶
CommitChange creates a file change and commits it.
func (*Scenario) CreateBranch ¶
CreateBranch creates and checks out a new branch and rebuilds the engine.
func (*Scenario) CreateBranchQuiet ¶
CreateBranchQuiet creates and checks out a new branch without rebuilding the engine.
func (*Scenario) ExpectBranch ¶
ExpectBranch asserts that the current branch is as expected.
func (*Scenario) ExpectBranchFixed ¶
ExpectBranchFixed asserts that a branch is considered "fixed" (no restack needed) by the engine.
func (*Scenario) ExpectBranchNotFixed ¶
ExpectBranchNotFixed asserts that a branch is NOT considered "fixed" by the engine.
func (*Scenario) ExpectStackStructure ¶
ExpectStackStructure asserts that the engine's parent-child relationships match the expected map.
func (*Scenario) RunCli ¶
RunCli executes a stackit CLI command and rebuilds the engine if it exists.
func (*Scenario) RunCliAndGetOutput ¶
RunCliAndGetOutput executes a stackit CLI command and returns its output. ANSI escape codes are stripped from the output for stable test assertions, since lipgloss v2 always generates ANSI codes regardless of terminal type.
func (*Scenario) RunExpectError ¶
RunExpectError executes a stackit CLI command and expects it to fail.
func (*Scenario) TrackBranch ¶
TrackBranch tracks a branch with a parent in the engine.
func (*Scenario) WithBinaryPath ¶
WithBinaryPath sets the path to the stackit binary for RunCli methods.
func (*Scenario) WithDiamondStack ¶
WithDiamondStack creates a diamond-shaped stack: main -> parent -> [child1, child2] This is useful for testing operations with parallel branches.
func (*Scenario) WithInProcess ¶
WithInProcess sets whether to use in-process CLI execution for RunCli methods.
func (*Scenario) WithInitialCommit ¶
WithInitialCommit creates an initial commit on the main branch.
func (*Scenario) WithLinearStack ¶
WithLinearStack creates a linear stack with the given branch names. Each branch is created as a child of the previous one, starting from trunk. Example: WithLinearStack("a", "b", "c") creates: main -> a -> b -> c
func (*Scenario) WithLinearStack3 ¶
WithLinearStack3 creates a linear stack: main -> a -> b -> c This is a convenience wrapper for WithLinearStack("a", "b", "c").
func (*Scenario) WithStack ¶
WithStack sets up a branch hierarchy. The map keys are branch names, and values are their parent branch names. It automatically creates a commit on each branch and tracks it.
func (*Scenario) WithUncommittedChange ¶
WithUncommittedChange creates an uncommitted change in the repository.