Step 7: Remaining commands — remove, verify, list, diff.
Remove: untrack files, remove manifest entries, save. 2 tests. Verify: check blobs against manifest hashes, report ok/mismatch/missing. 3 tests. List: return all tracked entries, CLI formats by type. 2 tests. Diff: compare stored blob vs current file, simple line diff. 3 tests. Each command in its own file (garden/<cmd>.go) for parallel development. Remove, verify, list implemented by parallel worktree agents; diff manual. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
94
garden/diff_test.go
Normal file
94
garden/diff_test.go
Normal file
@@ -0,0 +1,94 @@
|
||||
package garden
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDiffUnchangedFile(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
repoDir := filepath.Join(root, "repo")
|
||||
|
||||
g, err := Init(repoDir)
|
||||
if err != nil {
|
||||
t.Fatalf("Init: %v", err)
|
||||
}
|
||||
|
||||
testFile := filepath.Join(root, "testfile")
|
||||
if err := os.WriteFile(testFile, []byte("hello world\n"), 0o644); err != nil {
|
||||
t.Fatalf("writing test file: %v", err)
|
||||
}
|
||||
|
||||
if err := g.Add([]string{testFile}); err != nil {
|
||||
t.Fatalf("Add: %v", err)
|
||||
}
|
||||
|
||||
d, err := g.Diff(testFile)
|
||||
if err != nil {
|
||||
t.Fatalf("Diff: %v", err)
|
||||
}
|
||||
|
||||
if d != "" {
|
||||
t.Errorf("expected empty diff for unchanged file, got:\n%s", d)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffModifiedFile(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
repoDir := filepath.Join(root, "repo")
|
||||
|
||||
g, err := Init(repoDir)
|
||||
if err != nil {
|
||||
t.Fatalf("Init: %v", err)
|
||||
}
|
||||
|
||||
testFile := filepath.Join(root, "testfile")
|
||||
if err := os.WriteFile(testFile, []byte("original\n"), 0o644); err != nil {
|
||||
t.Fatalf("writing test file: %v", err)
|
||||
}
|
||||
|
||||
if err := g.Add([]string{testFile}); err != nil {
|
||||
t.Fatalf("Add: %v", err)
|
||||
}
|
||||
|
||||
// Modify the file on disk.
|
||||
if err := os.WriteFile(testFile, []byte("modified\n"), 0o644); err != nil {
|
||||
t.Fatalf("modifying test file: %v", err)
|
||||
}
|
||||
|
||||
d, err := g.Diff(testFile)
|
||||
if err != nil {
|
||||
t.Fatalf("Diff: %v", err)
|
||||
}
|
||||
|
||||
if d == "" {
|
||||
t.Fatal("expected non-empty diff for modified file")
|
||||
}
|
||||
|
||||
if !strings.Contains(d, "original") {
|
||||
t.Errorf("diff should contain old content 'original', got:\n%s", d)
|
||||
}
|
||||
if !strings.Contains(d, "modified") {
|
||||
t.Errorf("diff should contain new content 'modified', got:\n%s", d)
|
||||
}
|
||||
if !strings.Contains(d, "---") || !strings.Contains(d, "+++") {
|
||||
t.Errorf("diff should contain --- and +++ headers, got:\n%s", d)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffUntrackedPath(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
repoDir := filepath.Join(root, "repo")
|
||||
|
||||
g, err := Init(repoDir)
|
||||
if err != nil {
|
||||
t.Fatalf("Init: %v", err)
|
||||
}
|
||||
|
||||
_, err = g.Diff(filepath.Join(root, "nonexistent"))
|
||||
if err == nil {
|
||||
t.Fatal("expected error for untracked path")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user