Skip to content

Commit c95ade1

Browse files
feat: add USB fixture helpers for backup-mode testing (#3)
1 parent 9b81f46 commit c95ade1

4 files changed

Lines changed: 46 additions & 5 deletions

File tree

‎DEVELOPER_GUIDE.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Clone and verify:
2222
git clone https://github.com/git-fire/git-testkit.git
2323

2424
# or SSH
25-
# git clone git@github.com:git-fire/git-testkit.git
25+
git clone git@github.com:git-fire/git-testkit.git
2626

2727
cd git-testkit
2828
go test ./...
@@ -34,6 +34,7 @@ go test ./...
3434
- `scenarios.go`: fluent scenario builder and predefined multi-repo scenarios.
3535
- `snapshots.go`: snapshot/restore utilities for expensive test setup reuse.
3636
- `fixtures_test.go`: external package tests (`testutil_test`) that validate public API usage.
37+
- `usb_fixtures.go` / `usb_fixtures_test.go`: USB volume root and `.git-fire` config helpers for backup-mode style tests.
3738
- `scenarios_test.go`: package-internal tests for scenario/snapshot behavior.
3839

3940
## Design principles

‎fixtures.go‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,13 @@ func GetRemotes(t *testing.T, repoPath string) map[string]string {
218218
remainder = strings.TrimSpace(remainder)
219219
}
220220

221-
remainder = strings.TrimSuffix(remainder, " (fetch)")
222-
remainder = strings.TrimSuffix(remainder, " (push)")
221+
// Strip only the trailing git remote role suffix once so paths that end
222+
// with text like " (push)" are not damaged by sequential TrimSuffix calls.
223+
if strings.HasSuffix(remainder, " (fetch)") {
224+
remainder = strings.TrimSuffix(remainder, " (fetch)")
225+
} else if strings.HasSuffix(remainder, " (push)") {
226+
remainder = strings.TrimSuffix(remainder, " (push)")
227+
}
223228

224229
if name != "" && remainder != "" {
225230
remotes[name] = remainder

‎fixtures_test.go‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,31 @@ func TestCreateTestRepo_WithRemotePathContainingSpaces(t *testing.T) {
9999
}
100100
}
101101

102+
func TestCreateTestRepo_WithRemotePathContainingPushSuffix(t *testing.T) {
103+
tmpDir := t.TempDir()
104+
remotePath := filepath.Join(tmpDir, "origin (push)")
105+
if err := os.MkdirAll(remotePath, 0755); err != nil {
106+
t.Fatalf("Failed to create bare repo directory: %v", err)
107+
}
108+
testutil.RunGitCmd(t, tmpDir, "init", "--bare", remotePath)
109+
110+
repoPath := testutil.CreateTestRepo(t, testutil.RepoOptions{
111+
Name: "remote-push-suffix-repo",
112+
Remotes: map[string]string{
113+
"origin": remotePath,
114+
},
115+
})
116+
117+
remotes := testutil.GetRemotes(t, repoPath)
118+
originURL, exists := remotes["origin"]
119+
if !exists {
120+
t.Fatal("Expected 'origin' remote to be configured")
121+
}
122+
if originURL != remotePath {
123+
t.Fatalf("Expected origin URL %q, got %q", remotePath, originURL)
124+
}
125+
}
126+
102127
func TestCreateBareRemote(t *testing.T) {
103128
remotePath := testutil.CreateBareRemote(t, "test-remote")
104129

‎usb_fixtures.go‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,24 @@ func ReadUSBVolumeConfig(t *testing.T, root string) USBVolumeConfig {
167167
func AssertGitDirAt(t *testing.T, path string, wantBare bool) {
168168
t.Helper()
169169
if wantBare {
170-
if _, err := os.Stat(filepath.Join(path, "HEAD")); err != nil {
170+
headPath := filepath.Join(path, "HEAD")
171+
info, err := os.Stat(headPath)
172+
if err != nil {
171173
t.Fatalf("expected bare repo at %s: %v", path, err)
172174
}
175+
if info.IsDir() {
176+
t.Fatalf("expected bare repo HEAD file at %s", path)
177+
}
173178
return
174179
}
175-
if _, err := os.Stat(filepath.Join(path, ".git")); err != nil {
180+
gitPath := filepath.Join(path, ".git")
181+
info, err := os.Stat(gitPath)
182+
if err != nil {
176183
t.Fatalf("expected non-bare repo at %s: %v", path, err)
177184
}
185+
if !info.IsDir() {
186+
t.Fatalf("expected non-bare repo .git directory at %s", path)
187+
}
178188
}
179189

180190
func FileURLForPath(t *testing.T, path string) string {

0 commit comments

Comments
 (0)