testhelpers

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: 21 Imported by: 0

README

Test Helpers

This package provides testing utilities for the Stackit CLI Go port, ported from the TypeScript test infrastructure.

Overview

The testhelpers package provides:

  • Scene System: Reusable test scenarios with temporary Git repositories
  • Git Repository Helpers: Utilities for manipulating Git repos in tests
  • Assertions: Custom assertion helpers for branches and commits

Scene System

The scene system creates isolated test environments with temporary Git repositories.

Basic Usage
import (
    "testing"
    "github.com/getstackit/stackit/testhelpers"
)

func TestMyFeature(t *testing.T) {
    // Create a basic scene with a single commit
    scene := testhelpers.NewScene(t, testhelpers.BasicSceneSetup)
    
    // Use scene.Repo to interact with the Git repository
    err := scene.Repo.RunCliCommand([]string{"branch", "create", "feature"})
    require.NoError(t, err)
    
    // Assertions
    testhelpers.ExpectBranchesString(t, scene.Repo, "feature, main")
}
Custom Setup
func TestCustomScenario(t *testing.T) {
    customSetup := func(scene *testhelpers.Scene) error {
        // Create multiple commits
        scene.Repo.CreateChangeAndCommit("commit 1", "1")
        scene.Repo.CreateChangeAndCommit("commit 2", "2")
        
        // Create branches
        scene.Repo.CreateAndCheckoutBranch("parent")
        scene.Repo.CheckoutBranch("main")
        
        return nil
    }
    
    scene := testhelpers.NewScene(t, customSetup)
    // Test implementation...
}

Git Repository Helpers

The GitRepo type provides methods for Git operations:

Basic Operations
repo := scene.Repo

// Create commits
repo.CreateChangeAndCommit("content", "prefix")

// Branch operations
repo.CreateAndCheckoutBranch("feature")
repo.CheckoutBranch("main")
repo.DeleteBranch("old-branch")

// Get information
branch, _ := repo.CurrentBranchName()
ref, _ := repo.GetRef("HEAD")
messages, _ := repo.ListCurrentBranchCommitMessages()
Running CLI Commands
// Run a CLI command
err := repo.RunCliCommand([]string{"branch", "create", "feature"})

// Run a CLI command and get output
output, err := repo.RunCliCommandAndGetOutput([]string{"branch", "list"})

Assertions

Branch Assertions
// Assert branches as a slice
testhelpers.ExpectBranches(t, repo, []string{"main", "feature"})

// Assert branches as a comma-separated string (matches TypeScript API)
testhelpers.ExpectBranchesString(t, repo, "feature, main")
Commit Assertions
// Assert commits on a specific branch
testhelpers.ExpectCommits(t, repo, "main", []string{"Initial commit", "Second commit"})

// Assert commits as a comma-separated string (matches TypeScript API)
testhelpers.ExpectCommitsString(t, repo, "Initial commit, Second commit")

Scene Types

The following scene setups are available:

  • BasicSceneSetup: Creates a scene with a single commit on main branch

Additional scene types can be added as needed, following the pattern:

func MySceneSetup(scene *testhelpers.Scene) error {
    // Setup logic here
    return nil
}

Cleanup

Scenes automatically clean up temporary directories using t.Cleanup(). If the DEBUG environment variable is set, temporary directories are preserved for inspection.

Migration Notes

This package is a direct port of the TypeScript test infrastructure:

  • AbstractSceneScene
  • GitRepo class → GitRepo struct
  • expectBranchesExpectBranches / ExpectBranchesString
  • expectCommitsExpectCommits / ExpectCommitsString

The API is designed to be as similar as possible to the TypeScript version while following Go idioms.

GitHub API Mocking

The testhelpers package provides utilities for testing commands that interact with the GitHub API without making real API calls.

Mock GitHub Server

The NewMockGitHubServer and NewMockGitHubClient functions create a mock GitHub API server using Go's httptest package. This allows you to test GitHub API interactions locally without requiring authentication or hitting rate limits.

Basic Usage
import (
    "testing"
    "github.com/getstackit/stackit/testhelpers"
    "github.com/getstackit/stackit/internal/actions"
    "github.com/getstackit/stackit/internal/engine"
    "github.com/getstackit/stackit/internal/output"
)

func TestSubmitWithMockedGitHub(t *testing.T) {
    scene := testhelpers.NewScene(t, nil)
    
    // Set up your test scenario...
    scene.Repo.CreateChangeAndCommit("initial", "init")
    scene.Repo.RunGitCommand("config", "--local", "stackit.trunk", "main")
    scene.Repo.CreateAndCheckoutBranch("feature")
    scene.Repo.CreateChangeAndCommit("feature change", "feat")
    
    // Create engine and track branch
    eng, err := engine.NewEngine(engine.Options{
        RepoRoot:          scene.Dir,
        Trunk:             "main",
        MaxUndoStackDepth: engine.DefaultMaxUndoStackDepth,
    })
    require.NoError(t, err)
    err = eng.TrackBranch("feature", "main")
    require.NoError(t, err)
    
    // Create mocked GitHub client
    config := testhelpers.NewMockGitHubServerConfig()
    githubClient, owner, repo := testhelpers.NewMockGitHubClient(t, config)
    
    // Use mocked client in submit options
    opts := actions.SubmitOptions{
        Engine:       eng,
        Splog:        output.NewSplog(),
        DryRun:       false,
        NoEdit:       true,
        GitHubClient: githubClient,  // Inject mocked client
        GitHubOwner:  owner,
        GitHubRepo:   repo,
    }
    
    // Submit will use mocked client (push is automatically skipped)
    err = actions.SubmitAction(opts)
    require.NoError(t, err)
    
    // Verify PR was created in mock
    require.Greater(t, len(config.CreatedPRs), 0)
}
Mock Server Configuration

The MockGitHubServerConfig allows you to customize the mock server's behavior:

config := testhelpers.NewMockGitHubServerConfig()
config.Owner = "myorg"
config.Repo = "myrepo"

// Pre-populate existing PRs
prData := testhelpers.DefaultPRData()
prData.Head = "feature-branch"
prData.Number = 123
pr := testhelpers.NewSamplePullRequest(prData)
config.PRs["feature-branch"] = pr
config.UpdatedPRs[123] = pr

githubClient, owner, repo := testhelpers.NewMockGitHubClient(t, config)
Testing PR Operations

You can test individual PR operations using the mocked client:

func TestCreatePullRequest(t *testing.T) {
    config := testhelpers.NewMockGitHubServerConfig()
    client, owner, repo := testhelpers.NewMockGitHubClient(t, config)
    
    opts := git.CreatePROptions{
        Title: "Test PR",
        Head:  "feature",
        Base:  "main",
    }
    
    pr, err := git.CreatePullRequest(context.Background(), client, owner, repo, opts)
    require.NoError(t, err)
    require.NotNil(t, pr)
    require.Equal(t, 1, *pr.Number)
    
    // Verify in mock
    require.Greater(t, len(config.CreatedPRs), 0)
}
Test Fixtures

The github_fixtures.go file provides helper functions for creating test data:

  • DefaultPRData() - Creates a standard PR data structure
  • DraftPRData() - Creates a draft PR
  • PRWithReviewersData() - Creates a PR with reviewers
  • NewSamplePullRequest() - Converts PR data to a github.PullRequest
How It Works
  1. Mock Server: NewMockGitHubServer creates an httptest.Server that handles GitHub API endpoints
  2. Client Configuration: NewMockGitHubClient configures a github.Client to use the mock server's URL
  3. Automatic Cleanup: The mock server is automatically closed when the test completes via t.Cleanup()
  4. Push Skipping: When a mocked GitHub client is provided to SubmitAction, git push operations are automatically skipped
Supported Endpoints

The mock server currently supports:

  • POST /repos/{owner}/{repo}/pulls - Create pull request
  • PATCH /repos/{owner}/{repo}/pulls/{number} - Update pull request
  • GET /repos/{owner}/{repo}/pulls/{number} - Get pull request
  • GET /repos/{owner}/{repo}/pulls - List pull requests (with head filter)
  • POST /repos/{owner}/{repo}/pulls/{number}/requested_reviewers - Request reviewers
  • DELETE /repos/{owner}/{repo}/pulls/{number}/requested_reviewers - Remove reviewers
Limitations
  • The mock server is simplified and may not handle all edge cases
  • Some GitHub API features may not be fully implemented
  • For complex scenarios, consider using integration tests with a real GitHub repository

Documentation

Overview

Package testhelpers provides testing utilities for the Stackit CLI, including a scene system, Git repository helpers, and custom assertions.

Package testhelpers provides shared test utilities for CLI packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicSceneSetup

func BasicSceneSetup(scene *Scene) error

BasicSceneSetup is a setup function that creates a basic scene with a single commit.

func ExpectBranches

func ExpectBranches(t *testing.T, repo *GitRepo, expected []string)

ExpectBranches asserts that the repository has the expected branches. It filters out scene-related branches (prod, x2) and compares sorted lists.

func ExpectBranchesString

func ExpectBranchesString(t *testing.T, repo *GitRepo, expected string)

ExpectBranchesString asserts that the repository has the expected branches as a comma-separated sorted string (matching TypeScript API).

func ExpectCommits

func ExpectCommits(t *testing.T, repo *GitRepo, branch string, expected []string)

ExpectCommits asserts that the repository has the expected commit messages on the current branch.

func ExpectCommitsString

func ExpectCommitsString(t *testing.T, repo *GitRepo, expected string)

ExpectCommitsString asserts that the repository has the expected commit messages as a comma-separated string (matching TypeScript API).

func GetBinaryError

func GetBinaryError() error

GetBinaryError returns any error that occurred during binary building.

func GetSharedBinaryPath

func GetSharedBinaryPath() string

GetSharedBinaryPath returns the shared binary path, building it if necessary. This function is safe to call from any test package and will build the binary lazily on first access if it hasn't been set via SetSharedBinaryPath.

func InitialCommitSceneSetup

func InitialCommitSceneSetup(scene *Scene) error

InitialCommitSceneSetup creates a repo with a conventional "initial" commit.

func Must

func Must[T any](val T, err error) T

Must is a generic helper function that panics if err is not nil, otherwise returns the value. This is useful for test setup code where errors are not expected and should halt execution immediately. Requires Go 1.18+.

func NewMockGitHubClient

func NewMockGitHubClient(t *testing.T, config *MockGitHubServerConfig) (*github.Client, string, string)

NewMockGitHubClient creates a GitHub client configured to use a mock server

func NewMockGitHubClientInterface

func NewMockGitHubClientInterface(client *github.Client, owner, repo string, config *MockGitHubServerConfig) githubpkg.Client

NewMockGitHubClientInterface creates a GitHubClient interface implementation using the mock server

func NewMockGitHubServer

func NewMockGitHubServer(t *testing.T, config *MockGitHubServerConfig) *httptest.Server

NewMockGitHubServer creates an httptest server that mocks GitHub API endpoints

func NewSamplePullRequest

func NewSamplePullRequest(data SamplePRData) *github.PullRequest

NewSamplePullRequest creates a github.PullRequest from sample data

func NewTestPrInfo

func NewTestPrInfo(number int) *engine.PrInfo

NewTestPrInfo creates a PrInfo for testing with common defaults Most common case: open PR with just a number

func NewTestPrInfoClosed

func NewTestPrInfoClosed(number int) *engine.PrInfo

NewTestPrInfoClosed creates a PrInfo for a closed PR

func NewTestPrInfoDraft

func NewTestPrInfoDraft(number int) *engine.PrInfo

NewTestPrInfoDraft creates a PrInfo for a draft PR

func NewTestPrInfoEmpty

func NewTestPrInfoEmpty() *engine.PrInfo

NewTestPrInfoEmpty creates an empty PrInfo (useful for clearing PR info)

func NewTestPrInfoFull

func NewTestPrInfoFull(number int, title, body, state, base, url string, isDraft bool) *engine.PrInfo

NewTestPrInfoFull creates a PrInfo with all fields specified

func NewTestPrInfoMerged

func NewTestPrInfoMerged(number int, base string) *engine.PrInfo

NewTestPrInfoMerged creates a PrInfo for a merged PR

func NewTestPrInfoWithState

func NewTestPrInfoWithState(number int, state string) *engine.PrInfo

NewTestPrInfoWithState creates a PrInfo with a specific state

func NewTestPrInfoWithTitle

func NewTestPrInfoWithTitle(number int, title string) *engine.PrInfo

NewTestPrInfoWithTitle creates a PrInfo with a title

func NormalizeOutput

func NormalizeOutput(output string) string

NormalizeOutput removes variable parts of output and extra whitespace for comparison. It strips ANSI escape codes (lipgloss v2 always generates them) and removes empty lines to make test output comparisons more stable.

func SetSharedBinaryPath

func SetSharedBinaryPath(path string)

SetSharedBinaryPath sets the shared binary path for tests. This is called by TestMain in cli_test package.

func TestMain

func TestMain(m *testing.M, cleanup func())

TestMain provides a shared TestMain function for packages that need the stackit binary to be built once before running tests. Packages can use this by calling testhelpers.TestMain(m) in their own TestMain.

Types

type GitRepo

type GitRepo struct {
	Dir            string
	UserConfigPath string
}

GitRepo represents a Git repository for testing purposes. This is the Go equivalent of the TypeScript GitRepo class.

func NewGitRepo

func NewGitRepo(dir string) (*GitRepo, error)

NewGitRepo initializes a new Git repository in the specified directory using 'git init'.

func NewGitRepoFromExisting

func NewGitRepoFromExisting(t interface{ Helper() }, dir string) *GitRepo

NewGitRepoFromExisting wraps an existing Git repository directory (e.g., a worktree). This does not initialize or clone - it assumes the directory is already a valid git repo.

func NewGitRepoFromTemplate

func NewGitRepoFromTemplate(dir string, templatePath string) (*GitRepo, error)

NewGitRepoFromTemplate clones a repository from a local template using 'git clone --local'.

func NewGitRepoFromURL

func NewGitRepoFromURL(dir string, repoURL string) (*GitRepo, error)

NewGitRepoFromURL clones a repository from a remote URL.

func (*GitRepo) CheckoutBranch

func (r *GitRepo) CheckoutBranch(name string) error

CheckoutBranch checks out a branch.

func (*GitRepo) CheckoutDetached

func (r *GitRepo) CheckoutDetached(rev string) error

CheckoutDetached checks out a revision in detached HEAD state.

func (*GitRepo) CreateAndCheckoutBranch

func (r *GitRepo) CreateAndCheckoutBranch(name string) error

CreateAndCheckoutBranch creates and checks out a new branch.

func (*GitRepo) CreateBareRemote

func (r *GitRepo) CreateBareRemote(name string) (string, error)

CreateBareRemote creates a bare git repository to act as a remote. Returns the path to the bare repository.

func (*GitRepo) CreateBranch

func (r *GitRepo) CreateBranch(name string) error

CreateBranch creates a new branch without checking it out.

func (*GitRepo) CreateChange

func (r *GitRepo) CreateChange(textValue string, prefix string, unstaged bool) error

CreateChange creates a file change in the repository.

func (*GitRepo) CreateChangeAndAmend

func (r *GitRepo) CreateChangeAndAmend(textValue string, prefix string) error

CreateChangeAndAmend creates a file change and amends the last commit.

func (*GitRepo) CreateChangeAndCommit

func (r *GitRepo) CreateChangeAndCommit(textValue string, prefix string) error

CreateChangeAndCommit creates a file change and commits it.

func (*GitRepo) CreatePrecommitHook

func (r *GitRepo) CreatePrecommitHook(contents string) error

CreatePrecommitHook creates a pre-commit hook.

func (*GitRepo) CurrentBranchName

func (r *GitRepo) CurrentBranchName() (string, error)

CurrentBranchName returns the name of the current branch.

func (*GitRepo) DeleteBranch

func (r *GitRepo) DeleteBranch(name string) error

DeleteBranch deletes a branch.

func (*GitRepo) ForcePushBranch

func (r *GitRepo) ForcePushBranch(remote, branch string) error

ForcePushBranch force pushes a branch to a remote.

func (*GitRepo) GetBranchSHA

func (r *GitRepo) GetBranchSHA(branch string) (string, error)

GetBranchSHA returns the SHA of a branch.

func (*GitRepo) GetCommitCount

func (r *GitRepo) GetCommitCount(from, to string) (int, error)

GetCommitCount returns the number of commits between two refs.

func (*GitRepo) GetCurrentSHA

func (r *GitRepo) GetCurrentSHA() (string, error)

GetCurrentSHA returns the SHA of HEAD.

func (*GitRepo) GetLocalBranches

func (r *GitRepo) GetLocalBranches() ([]string, error)

GetLocalBranches returns a list of all local branches.

func (*GitRepo) GetRef

func (r *GitRepo) GetRef(refName string) (string, error)

GetRef returns the SHA of a ref.

func (*GitRepo) GetRevision

func (r *GitRepo) GetRevision(rev string) (string, error)

GetRevision returns the SHA of a revision (branch, tag, or commit reference).

func (*GitRepo) HasUnstagedChanges

func (r *GitRepo) HasUnstagedChanges() (bool, error)

HasUnstagedChanges checks if there are unstaged changes to tracked files.

func (*GitRepo) HasUntrackedFiles

func (r *GitRepo) HasUntrackedFiles() (bool, error)

HasUntrackedFiles checks if there are untracked files.

func (*GitRepo) IsAncestor

func (r *GitRepo) IsAncestor(ancestor, descendant string) (bool, error)

IsAncestor checks if the first ref is an ancestor of the second ref.

func (*GitRepo) ListCurrentBranchCommitMessages

func (r *GitRepo) ListCurrentBranchCommitMessages() ([]string, error)

ListCurrentBranchCommitMessages returns the commit messages on the current branch.

func (*GitRepo) MarkMergeConflictsAsResolved

func (r *GitRepo) MarkMergeConflictsAsResolved() error

MarkMergeConflictsAsResolved marks merge conflicts as resolved.

func (*GitRepo) MergeBranch

func (r *GitRepo) MergeBranch(branch, mergeIn string) error

MergeBranch merges a branch into another.

func (*GitRepo) PushBranch

func (r *GitRepo) PushBranch(remote, branch string) error

PushBranch pushes a branch to a remote.

func (*GitRepo) RebaseInProgress

func (r *GitRepo) RebaseInProgress() bool

RebaseInProgress checks if a rebase is in progress.

func (*GitRepo) ResolveMergeConflicts

func (r *GitRepo) ResolveMergeConflicts() error

ResolveMergeConflicts resolves merge conflicts by accepting theirs.

func (*GitRepo) RunCliCommand

func (r *GitRepo) RunCliCommand(command []string) error

RunCliCommand executes a Stackit CLI command in the repository directory.

func (*GitRepo) RunCliCommandAndGetOutput

func (r *GitRepo) RunCliCommandAndGetOutput(command []string) (string, error)

RunCliCommandAndGetOutput executes a Stackit CLI command and returns its output.

func (*GitRepo) RunGitCommand

func (r *GitRepo) RunGitCommand(args ...string) error

RunGitCommand executes a git command and returns an error if it fails.

func (*GitRepo) RunGitCommandAndGetOutput

func (r *GitRepo) RunGitCommandAndGetOutput(args ...string) (string, error)

RunGitCommandAndGetOutput executes a git command and returns its output.

func (*GitRepo) TrackBranch

func (r *GitRepo) TrackBranch(branch string, parentBranch string) error

TrackBranch tracks a branch using the CLI.

type MockGitHubClient

type MockGitHubClient struct {
	// contains filtered or unexported fields
}

MockGitHubClient implements githubpkg.Client using the mock server

func (*MockGitHubClient) BatchGetPRChecksStatus

func (c *MockGitHubClient) BatchGetPRChecksStatus(ctx context.Context, branchNames []string) (map[string]*githubpkg.CheckStatus, error)

BatchGetPRChecksStatus returns the check status for multiple branches

func (*MockGitHubClient) BatchGetPRTitles

func (c *MockGitHubClient) BatchGetPRTitles(_ context.Context, _, _ string, prNumbers []int) (map[int]string, error)

BatchGetPRTitles returns synthetic titles for testing

func (*MockGitHubClient) ClosePullRequest

func (c *MockGitHubClient) ClosePullRequest(ctx context.Context, owner, repo string, prNumber int) error

ClosePullRequest closes a pull request

func (*MockGitHubClient) CreatePRComment

func (c *MockGitHubClient) CreatePRComment(ctx context.Context, owner, repo string, prNumber int, body string) (int64, error)

CreatePRComment creates a new comment on a pull request

func (*MockGitHubClient) CreatePullRequest

func (c *MockGitHubClient) CreatePullRequest(ctx context.Context, owner, repo string, opts githubpkg.CreatePROptions) (*githubpkg.PullRequestInfo, error)

CreatePullRequest creates a new pull request

func (*MockGitHubClient) DeletePRComment

func (c *MockGitHubClient) DeletePRComment(ctx context.Context, owner, repo string, commentID int64) error

DeletePRComment deletes a pull request comment

func (*MockGitHubClient) GetAllowedMergeMethods

func (c *MockGitHubClient) GetAllowedMergeMethods(_ context.Context) (*githubpkg.MergeMethodSettings, error)

GetAllowedMergeMethods returns the allowed merge methods for the repository

func (*MockGitHubClient) GetCurrentUser

func (c *MockGitHubClient) GetCurrentUser(_ context.Context) (string, error)

GetCurrentUser returns a mock GitHub username

func (*MockGitHubClient) GetOwnerRepo

func (c *MockGitHubClient) GetOwnerRepo() (string, string)

GetOwnerRepo returns the repository owner and name

func (*MockGitHubClient) GetPRChecksStatus

func (c *MockGitHubClient) GetPRChecksStatus(ctx context.Context, branchName string) (*githubpkg.CheckStatus, error)

GetPRChecksStatus returns the check status for a PR

func (*MockGitHubClient) GetPullRequest

func (c *MockGitHubClient) GetPullRequest(ctx context.Context, owner, repo string, prNumber int) (*githubpkg.PullRequestInfo, error)

GetPullRequest gets a pull request by number

func (*MockGitHubClient) GetPullRequestByBranch

func (c *MockGitHubClient) GetPullRequestByBranch(ctx context.Context, owner, repo, branchName string) (*githubpkg.PullRequestInfo, error)

GetPullRequestByBranch gets a pull request for a branch

func (*MockGitHubClient) ListPRComments

func (c *MockGitHubClient) ListPRComments(ctx context.Context, owner, repo string, prNumber int) ([]githubpkg.PRComment, error)

ListPRComments lists all comments on a pull request

func (*MockGitHubClient) MergePullRequest

func (c *MockGitHubClient) MergePullRequest(_ context.Context, _ string, _ githubpkg.MergePROptions) error

MergePullRequest merges a pull request using the specified merge method

func (*MockGitHubClient) UpdatePRComment

func (c *MockGitHubClient) UpdatePRComment(ctx context.Context, owner, repo string, commentID int64, body string) error

UpdatePRComment updates an existing pull request comment

func (*MockGitHubClient) UpdatePullRequest

func (c *MockGitHubClient) UpdatePullRequest(ctx context.Context, owner, repo string, prNumber int, opts githubpkg.UpdatePROptions) ([]string, error)

UpdatePullRequest updates an existing pull request

type MockGitHubServerConfig

type MockGitHubServerConfig struct {
	// PRs maps branch names to PR data for GetPullRequestByBranch
	PRs map[string]*github.PullRequest
	// CreatedPRs stores PRs that were created (for testing)
	CreatedPRs []*github.PullRequest
	// UpdatedPRs stores PRs that were updated (for testing)
	UpdatedPRs map[int]*github.PullRequest
	// ErrorResponses maps endpoint+method to error responses
	ErrorResponses map[string]error
	// Owner and Repo for the mock server
	Owner string
	Repo  string
	// contains filtered or unexported fields
}

MockGitHubServerConfig configures the behavior of a mock GitHub server

func NewMockGitHubServerConfig

func NewMockGitHubServerConfig() *MockGitHubServerConfig

NewMockGitHubServerConfig creates a new mock server config with defaults

type SamplePRData

type SamplePRData struct {
	Number        int
	Title         string
	Body          string
	Head          string
	Base          string
	HTMLURL       string
	Draft         bool
	State         string
	Reviewers     []string
	TeamReviewers []string
}

SamplePRData provides common PR data for testing

func ClosedPRData

func ClosedPRData() SamplePRData

ClosedPRData returns PR data for a closed PR

func DefaultPRData

func DefaultPRData() SamplePRData

DefaultPRData returns a default PR data structure for testing

func DraftPRData

func DraftPRData() SamplePRData

DraftPRData returns PR data for a draft PR

func MergedPRData

func MergedPRData() SamplePRData

MergedPRData returns PR data for a merged PR

func PRWithReviewersData

func PRWithReviewersData(reviewers []string, teamReviewers []string) SamplePRData

PRWithReviewersData returns PR data with reviewers

type Scene

type Scene struct {
	Dir  string
	Repo *GitRepo
	// contains filtered or unexported fields
}

Scene represents a test scene with a temporary directory and Git repository. This is the Go equivalent of the TypeScript AbstractScene.

func NewRemoteSceneParallel

func NewRemoteSceneParallel(t *testing.T) *Scene

NewRemoteSceneParallel creates a parallel-safe scene with an initial commit, a local bare "origin" remote, and main pushed to that remote.

func NewScene

func NewScene(t *testing.T, setup SceneSetup) *Scene

NewScene creates a new test scene with a temporary directory and Git repository. It automatically handles cleanup using t.Cleanup(). NOTE: This function uses os.Chdir() and is NOT safe for parallel tests. Use NewSceneParallel for tests that can run in parallel.

func NewSceneParallel

func NewSceneParallel(t *testing.T, setup SceneSetup) *Scene

NewSceneParallel creates a new test scene that is safe for parallel tests. Unlike NewScene, this does NOT change the working directory. Tests using this must ensure all git operations use explicit directory paths (e.g., via scene.Repo methods or cmd.Dir = scene.Dir).

type SceneSetup

type SceneSetup func(*Scene) error

SceneSetup is a function type for setting up a scene.

Directories

Path Synopsis
Package inprocess provides in-process CLI execution for tests.
Package inprocess provides in-process CLI execution for tests.
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.
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.

Jump to

Keyboard shortcuts

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