(t *testing.T)
| 82 | } |
| 83 | |
| 84 | func TestFileTracker_ModifiedFiles(t *testing.T) { |
| 85 | // Create a temporary directory for testing |
| 86 | tempDir, err := os.MkdirTemp("", "file-tracker-test") |
| 87 | if err != nil { |
| 88 | t.Fatalf("Failed to create temp dir: %v", err) |
| 89 | } |
| 90 | defer os.RemoveAll(tempDir) |
| 91 | |
| 92 | // Initialize git repository in temp directory |
| 93 | gitCmd := []string{"git", "init"} |
| 94 | if err := runCommandInDir(gitCmd, tempDir); err != nil { |
| 95 | t.Skipf("Skipping test - git not available or failed to init: %v", err) |
| 96 | } |
| 97 | |
| 98 | // Change to temp directory |
| 99 | oldWd, _ := os.Getwd() |
| 100 | defer func() { |
| 101 | _ = os.Chdir(oldWd) |
| 102 | }() |
| 103 | if err := os.Chdir(tempDir); err != nil { |
| 104 | t.Fatalf("Failed to change to temp directory: %v", err) |
| 105 | } |
| 106 | |
| 107 | // Create file tracker |
| 108 | tracker := NewFileTracker() |
| 109 | |
| 110 | // Create existing file |
| 111 | testFile := filepath.Join(tempDir, "existing.md") |
| 112 | originalContent := "# Original Content" |
| 113 | if err := os.WriteFile(testFile, []byte(originalContent), 0644); err != nil { |
| 114 | t.Fatalf("Failed to write test file: %v", err) |
| 115 | } |
| 116 | |
| 117 | // Track modification BEFORE modifying the file |
| 118 | tracker.TrackModified(testFile) |
| 119 | |
| 120 | // Now modify the file |
| 121 | modifiedContent := "# Modified Content" |
| 122 | if err := os.WriteFile(testFile, []byte(modifiedContent), 0644); err != nil { |
| 123 | t.Fatalf("Failed to modify test file: %v", err) |
| 124 | } |
| 125 | |
| 126 | // Verify tracking |
| 127 | if len(tracker.CreatedFiles) != 0 { |
| 128 | t.Errorf("Expected 0 created files, got %d", len(tracker.CreatedFiles)) |
| 129 | } |
| 130 | if len(tracker.ModifiedFiles) != 1 { |
| 131 | t.Errorf("Expected 1 modified file, got %d", len(tracker.ModifiedFiles)) |
| 132 | } |
| 133 | |
| 134 | // Test staging files |
| 135 | if err := tracker.StageAllFiles(false); err != nil { |
| 136 | t.Errorf("Failed to stage files: %v", err) |
| 137 | } |
| 138 | |
| 139 | // Rollback should not delete modified files (only created ones) |
| 140 | if err := tracker.RollbackCreatedFiles(false); err != nil { |
| 141 | t.Errorf("Failed to rollback files: %v", err) |
nothing calls this directly
no test coverage detected