scenario

package
v0.17.15 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 14 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

type InProcessRunner func(workDir string, args ...string) (string, error)

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

func NewRemoteScenario(t *testing.T) *Scenario

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

func (s *Scenario) Checkout(branch string) *Scenario

Checkout checks out a branch and rebuilds the engine.

func (*Scenario) CheckoutQuiet

func (s *Scenario) CheckoutQuiet(branch string) *Scenario

CheckoutQuiet checks out a branch without rebuilding the engine.

func (*Scenario) Commit

func (s *Scenario) Commit(message string) *Scenario

Commit creates an empty commit with the given message.

func (*Scenario) CommitChange

func (s *Scenario) CommitChange(name, message string) *Scenario

CommitChange creates a file change and commits it.

func (*Scenario) CreateBranch

func (s *Scenario) CreateBranch(name string) *Scenario

CreateBranch creates and checks out a new branch and rebuilds the engine.

func (*Scenario) CreateBranchQuiet

func (s *Scenario) CreateBranchQuiet(name string) *Scenario

CreateBranchQuiet creates and checks out a new branch without rebuilding the engine.

func (*Scenario) ExpectBranch

func (s *Scenario) ExpectBranch(expected string) *Scenario

ExpectBranch asserts that the current branch is as expected.

func (*Scenario) ExpectBranchFixed

func (s *Scenario) ExpectBranchFixed(branch string) *Scenario

ExpectBranchFixed asserts that a branch is considered "fixed" (no restack needed) by the engine.

func (*Scenario) ExpectBranchNotFixed

func (s *Scenario) ExpectBranchNotFixed(branch string) *Scenario

ExpectBranchNotFixed asserts that a branch is NOT considered "fixed" by the engine.

func (*Scenario) ExpectStackStructure

func (s *Scenario) ExpectStackStructure(expected map[string]string) *Scenario

ExpectStackStructure asserts that the engine's parent-child relationships match the expected map.

func (*Scenario) Log

func (s *Scenario) Log(args ...any)

Log logs a message using the testing.T object.

func (*Scenario) Logf

func (s *Scenario) Logf(format string, args ...any)

Logf logs a formatted message using the testing.T object.

func (*Scenario) Rebuild

func (s *Scenario) Rebuild() *Scenario

Rebuild refreshes the engine's internal state from the Git repository.

func (*Scenario) Run

func (s *Scenario) Run(args ...string) *Scenario

Run is an alias for RunCli for backward compatibility in some tests.

func (*Scenario) RunCli

func (s *Scenario) RunCli(args ...string) *Scenario

RunCli executes a stackit CLI command and rebuilds the engine if it exists.

func (*Scenario) RunCliAndGetOutput

func (s *Scenario) RunCliAndGetOutput(args ...string) (string, error)

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

func (s *Scenario) RunExpectError(args ...string) *Scenario

RunExpectError executes a stackit CLI command and expects it to fail.

func (*Scenario) RunGit

func (s *Scenario) RunGit(args ...string) *Scenario

RunGit runs a git command in the scenario's repository.

func (*Scenario) TrackBranch

func (s *Scenario) TrackBranch(branch, parent string) *Scenario

TrackBranch tracks a branch with a parent in the engine.

func (*Scenario) WithBinaryPath

func (s *Scenario) WithBinaryPath(path string) *Scenario

WithBinaryPath sets the path to the stackit binary for RunCli methods.

func (*Scenario) WithDiamondStack

func (s *Scenario) WithDiamondStack() *Scenario

WithDiamondStack creates a diamond-shaped stack: main -> parent -> [child1, child2] This is useful for testing operations with parallel branches.

func (*Scenario) WithInProcess

func (s *Scenario) WithInProcess(inProcess bool) *Scenario

WithInProcess sets whether to use in-process CLI execution for RunCli methods.

func (*Scenario) WithInitialCommit

func (s *Scenario) WithInitialCommit() *Scenario

WithInitialCommit creates an initial commit on the main branch.

func (*Scenario) WithLinearStack

func (s *Scenario) WithLinearStack(names ...string) *Scenario

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

func (s *Scenario) WithLinearStack3() *Scenario

WithLinearStack3 creates a linear stack: main -> a -> b -> c This is a convenience wrapper for WithLinearStack("a", "b", "c").

func (*Scenario) WithStack

func (s *Scenario) WithStack(structure map[string]string) *Scenario

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

func (s *Scenario) WithUncommittedChange(name string) *Scenario

WithUncommittedChange creates an uncommitted change in the repository.

Jump to

Keyboard shortcuts

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