(t *testing.T)
| 184 | } |
| 185 | |
| 186 | func TestFileTracker_RollbackAllFiles(t *testing.T) { |
| 187 | // Create a temporary directory for testing |
| 188 | tempDir, err := os.MkdirTemp("", "file-tracker-rollback-test") |
| 189 | if err != nil { |
| 190 | t.Fatalf("Failed to create temp dir: %v", err) |
| 191 | } |
| 192 | defer os.RemoveAll(tempDir) |
| 193 | |
| 194 | // Initialize git repository in temp directory |
| 195 | gitCmd := []string{"git", "init"} |
| 196 | if err := runCommandInDir(gitCmd, tempDir); err != nil { |
| 197 | t.Skipf("Skipping test - git not available or failed to init: %v", err) |
| 198 | } |
| 199 | |
| 200 | // Change to temp directory |
| 201 | oldWd, _ := os.Getwd() |
| 202 | defer func() { |
| 203 | _ = os.Chdir(oldWd) |
| 204 | }() |
| 205 | if err := os.Chdir(tempDir); err != nil { |
| 206 | t.Fatalf("Failed to change to temp directory: %v", err) |
| 207 | } |
| 208 | |
| 209 | // Create file tracker |
| 210 | tracker := NewFileTracker() |
| 211 | |
| 212 | // Create an existing file |
| 213 | existingFile := filepath.Join(tempDir, "existing.md") |
| 214 | originalContent := "# Original Content" |
| 215 | if err := os.WriteFile(existingFile, []byte(originalContent), 0644); err != nil { |
| 216 | t.Fatalf("Failed to write existing file: %v", err) |
| 217 | } |
| 218 | |
| 219 | // Track modification before modifying |
| 220 | tracker.TrackModified(existingFile) |
| 221 | modifiedContent := "# Modified Content" |
| 222 | if err := os.WriteFile(existingFile, []byte(modifiedContent), 0644); err != nil { |
| 223 | t.Fatalf("Failed to modify existing file: %v", err) |
| 224 | } |
| 225 | |
| 226 | // Create a new file |
| 227 | newFile := filepath.Join(tempDir, "new.md") |
| 228 | tracker.TrackCreated(newFile) |
| 229 | if err := os.WriteFile(newFile, []byte("# New Content"), 0644); err != nil { |
| 230 | t.Fatalf("Failed to write new file: %v", err) |
| 231 | } |
| 232 | |
| 233 | // Rollback all files |
| 234 | if err := tracker.RollbackAllFiles(false); err != nil { |
| 235 | t.Errorf("Failed to rollback all files: %v", err) |
| 236 | } |
| 237 | |
| 238 | // Verify new file was deleted |
| 239 | if _, err := os.Stat(newFile); !os.IsNotExist(err) { |
| 240 | t.Errorf("New file %s should have been deleted", newFile) |
| 241 | } |
| 242 | |
| 243 | // Verify existing file was restored to original content |
nothing calls this directly
no test coverage detected