Skip to content

Commit d76ee40

Browse files
authored
Harden git watcher test setup (#18)
1 parent a8a4302 commit d76ee40

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

git/watcher_test.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,29 @@ func setupTestRepo(t *testing.T) (string, storage.Storage, graph.Graph) {
1717
t.Helper()
1818
dir := t.TempDir()
1919

20-
// Initialize a git repo
20+
runGit := func(args ...string) {
21+
t.Helper()
22+
cmd := exec.Command("git", args...)
23+
out, err := cmd.CombinedOutput()
24+
if err != nil {
25+
t.Fatalf("git %v: %s: %v", args, out, err)
26+
}
27+
}
28+
2129
cmd := exec.Command("git", "init", dir)
2230
if out, err := cmd.CombinedOutput(); err != nil {
2331
t.Fatalf("git init: %s: %v", out, err)
2432
}
2533

26-
// Configure git user for commits
27-
cmd = exec.Command("git", "-C", dir, "config", "user.email", "test@test.com")
28-
cmd.Run()
29-
cmd = exec.Command("git", "-C", dir, "config", "user.name", "Test")
30-
cmd.Run()
34+
runGit("-C", dir, "config", "user.email", "test@test.com")
35+
runGit("-C", dir, "config", "user.name", "Test")
36+
runGit("-C", dir, "config", "commit.gpgsign", "false")
3137

32-
// Create a file and initial commit
3338
if err := os.WriteFile(filepath.Join(dir, "main.go"), []byte("package main\n"), 0o644); err != nil {
3439
t.Fatal(err)
3540
}
36-
exec.Command("git", "-C", dir, "add", ".").Run()
37-
exec.Command("git", "-C", dir, "commit", "-m", "init").Run()
41+
runGit("-C", dir, "add", ".")
42+
runGit("-C", dir, "commit", "-m", "init")
3843

3944
dbDir := t.TempDir()
4045
store, err := storage.NewStore(filepath.Join(dbDir, "test.db"))

0 commit comments

Comments
 (0)