Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ go test ./...
## Project structure

- `fixtures.go`: base repo creation and command helpers.
- `sanitize_fixtures.go`: reusable sanitize/rewrite fixtures plus blocked-string scan/assert helpers.
- `scenarios.go`: fluent scenario builder and predefined multi-repo scenarios.
- `snapshots.go`: snapshot/restore utilities for expensive test setup reuse.
- `fixtures_test.go`: external package tests (`testutil_test`) that validate public API usage.
- `sanitize_fixtures_test.go`: coverage tests for blocked-string detection/removal across content/history/refs/paths.
- `usb_fixtures.go` / `usb_fixtures_test.go`: USB volume root and `.git-fire` config helpers for backup-mode style tests.
- `scenarios_test.go`: package-internal tests for scenario/snapshot behavior.

Expand Down Expand Up @@ -74,6 +76,18 @@ Common usage split:
- `CreateTestRepo`: fast setup for single-repo state.
- `NewScenario`: multi-repo topologies and fluent setup.
- `SnapshotRepo`/`RestoreSnapshot`: performance optimization for repeated expensive setups.
- `CreateRewriteValidationFixture` + blocked-string assertions: sanitize/rewrite validation against file contents, commit messages, refs, and paths.

Sanitize/rewrite focused validation loop:

```bash
# Run only sanitize/rewrite fixture and assertion tests.
go test ./... -run 'RewriteValidation|BlockedStringCoverage'

# Full required local gate.
go vet ./...
go test ./...
```

## Adding new helpers

Expand Down
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ go get github.com/git-fire/git-testkit
- Repository fixtures (`CreateTestRepo`, `CreateBareRemote`, `RunGitCmd`)
- Scenario builders for common multi-repo states (`NewScenario`, conflict/worktree helpers)
- Snapshot helpers for capturing and restoring repository state in tests
- Sanitize/rewrite validation helpers for blocked-string coverage across content/history/refs/paths

## API overview

Expand All @@ -38,6 +39,8 @@ go get github.com/git-fire/git-testkit
- `NewScenario(t)` returns a fluent builder for multi-repo test topologies.
- `SnapshotRepo(t, path)` and `RestoreSnapshot(t, snap)` speed up repeated fixture setup.
- `IsDirty`, `GetCurrentSHA`, `GetBranches`, `GetRemotes` provide common assertions/helpers.
- `CreateRewriteValidationFixture(t, opts)` seeds blocked strings across file contents, commit messages, refs, and paths.
- `AssertBlockedStringCoverageDetected` and `AssertBlockedStringCoverageRemoved` validate sanitize/rewrite coverage before/after rewriting.

## Quickstart for using in tests

Expand Down Expand Up @@ -113,6 +116,33 @@ func TestUsingSnapshot(t *testing.T) {
}
```

### Validate sanitize/rewrite coverage

```go
func TestRewriteRemovesBlockedString(t *testing.T) {
fixture := testutil.CreateRewriteValidationFixture(t, testutil.RewriteValidationFixtureOptions{
Name: "rewrite-fixture",
BlockedString: "blockedtoken",
})

// Confirm fixture coverage before running your rewrite logic.
testutil.AssertBlockedStringCoverageDetected(t, fixture.RepoPath, fixture.BlockedString)

// Run your sanitizer/rewrite command against fixture.RepoPath here.
// Example:
// testutil.RunGitCmd(t, fixture.RepoPath, "filter-branch", ...)

// Validate the blocked string is removed from all tracked surfaces.
testutil.AssertBlockedStringCoverageRemoved(t, fixture.RepoPath, fixture.BlockedString)
}
```

Run just sanitize/rewrite-focused tests:

```bash
go test ./... -run 'RewriteValidation|BlockedStringCoverage'
```

## Notes

- Snapshots are intended for deterministic test fixtures and only restore regular files/directories.
Expand Down
2 changes: 2 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// remote, diverged clones, worktrees, conflict states).
// - [SnapshotRepo] / [RestoreSnapshot] for capturing expensive fixture state
// once and restoring it cheaply across subtests.
// - [CreateRewriteValidationFixture] plus blocked-string assertions for
// sanitize/rewrite validation across content, commit history, refs, and paths.
//
// All helpers integrate with Go's testing.T: repositories are created inside
// t.TempDir() and cleaned up automatically, and setup failures call t.Fatalf
Expand Down
Loading
Loading