End-to-end tests for gh-stack that compile and run the actual binary against isolated git repositories.
# Run all E2E tests
make e2e
# Run specific test
go test -v ./e2e/ -run TestCascade
# Run with race detection
go test -race -v ./e2e/...
# Run unit tests only (faster)
make test-unit
# Run everything
make testmain_test.go- TestMain compiles binary once before all testshelpers_test.go- TestEnv struct, Result type, core helpersscenario_helpers_test.go- Conflict and remote simulation helperssmoke_test.go- Basic smoke testinit_create_test.go- Init and create command testscascade_test.go- Restack tests including conflict recoveryadopt_orphan_test.go- Adopt and orphan command testspush_test.go- Push command testserror_cases_test.go- Error handling testschaos_manual_git_test.go- Manual git operation resiliencechaos_remote_test.go- Remote sync scenario tests
- TestMain compiles
gh-stackbinary once to a temp directory - Each test creates an isolated git repo via
NewTestEnv(t)usingt.TempDir() - Tests execute the binary via subprocess and verify behavior
- Temp directories are automatically cleaned up by Go's testing framework
TestEnv provides:
Run(args...)- Execute gh-stack, returns Result (doesn't fail on error)MustRun(args...)- Execute gh-stack, fails test on non-zero exitGit(args...)- Execute git commands directlyWriteFile(name, content)- Create files in the test repoCreateCommit(msg)- Create a commit with a unique fileAssert*()- Various assertions (branch, ancestry, rebase state)
func TestMyScenario(t *testing.T) {
// Create isolated git repo
env := NewTestEnv(t) // or NewTestEnvWithRemote(t) for push tests
// Initialize stack
env.MustRun("init")
// Use env.Run() for commands that might fail
result := env.Run("some-command")
if result.Failed() {
// handle or check error
}
// Use env.MustRun() for commands that must succeed
env.MustRun("create", "feature-1")
// Use env.Git() for direct git operations
env.Git("checkout", "main")
// Use assertions
env.AssertBranch("feature-1")
env.AssertStackParent("feature-1", "main")
env.AssertAncestor("main", "feature-1")
}E2E tests run as part of the standard test suite in GitHub Actions. The CI workflow configures git identity for the tests:
- name: Configure git for E2E tests
run: |
git config --global user.email "ci@github.com"
git config --global user.name "CI"
git config --global init.defaultBranch main