test: replace manual os.Chdir with t.Chdir in tests (#457)
Replaces manual working directory save/restore patterns with Go's built-in `t.Chdir()` helper across 23 test files. The manual pattern involved calling `os.Getwd()` to save the original directory, using `defer os.Chdir(origWd)` for restoration, and manually handling errors during directory changes. This boilerplate has been replaced with single `t.Chdir(path)` calls that handle cleanup automatically. The `t.Chdir()` method automatically restores the working directory when the test completes, eliminating the need for manual defer statements and error handling. Total: ~75 instances replaced (assuming Claude's math is right) Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -141,15 +141,11 @@ func TestDetectPrefix(t *testing.T) {
|
||||
|
||||
t.Run("empty database defaults to dir name", func(t *testing.T) {
|
||||
// Change to temp dir so we can control directory name
|
||||
origWd, _ := os.Getwd()
|
||||
namedDir := filepath.Join(tempDir, "myproject")
|
||||
if err := os.MkdirAll(namedDir, 0o755); err != nil {
|
||||
t.Fatalf("Failed to create named dir: %v", err)
|
||||
}
|
||||
if err := os.Chdir(namedDir); err != nil {
|
||||
t.Fatalf("Failed to chdir: %v", err)
|
||||
}
|
||||
defer func() { _ = os.Chdir(origWd) }()
|
||||
t.Chdir(namedDir)
|
||||
|
||||
memStore := memory.New(filepath.Join(beadsDir, "issues.jsonl"))
|
||||
prefix, err := detectPrefix(beadsDir, memStore)
|
||||
|
||||
Reference in New Issue
Block a user