MCPcopy Create free account
hub / github.com/github/gh-aw / TestFileTracker_CreationAndTracking

Function TestFileTracker_CreationAndTracking

pkg/cli/file_tracker_test.go:15–82  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestFileTracker_CreationAndTracking(t *testing.T) {
16 // Create a temporary directory for testing
17 tempDir, err := os.MkdirTemp("", "file-tracker-test")
18 if err != nil {
19 t.Fatalf("Failed to create temp dir: %v", err)
20 }
21 defer os.RemoveAll(tempDir)
22
23 // Initialize git repository in temp directory
24 gitCmd := []string{"git", "init"}
25 if err := runCommandInDir(gitCmd, tempDir); err != nil {
26 t.Skipf("Skipping test - git not available or failed to init: %v", err)
27 }
28
29 // Change to temp directory
30 oldWd, _ := os.Getwd()
31 defer func() {
32 _ = os.Chdir(oldWd)
33 }()
34 if err := os.Chdir(tempDir); err != nil {
35 t.Fatalf("Failed to change to temp directory: %v", err)
36 }
37
38 // Create file tracker
39 tracker := NewFileTracker()
40
41 // Create test files
42 testFile1 := filepath.Join(tempDir, "test1.md")
43 testFile2 := filepath.Join(tempDir, "test2.lock.yml")
44
45 // Create first file and track it
46 content1 := "# Test Workflow 1"
47 if err := os.WriteFile(testFile1, []byte(content1), 0644); err != nil {
48 t.Fatalf("Failed to write test file 1: %v", err)
49 }
50 tracker.TrackCreated(testFile1)
51
52 // Create second file and track it
53 content2 := "name: test-workflow"
54 if err := os.WriteFile(testFile2, []byte(content2), 0644); err != nil {
55 t.Fatalf("Failed to write test file 2: %v", err)
56 }
57 tracker.TrackCreated(testFile2)
58
59 // Verify tracking
60 allFiles := tracker.GetAllFiles()
61 if len(allFiles) != 2 {
62 t.Errorf("Expected 2 tracked files, got %d", len(allFiles))
63 }
64
65 // Test staging files
66 if err := tracker.StageAllFiles(false); err != nil {
67 t.Errorf("Failed to stage files: %v", err)
68 }
69
70 // Test rollback
71 if err := tracker.RollbackCreatedFiles(false); err != nil {
72 t.Errorf("Failed to rollback files: %v", err)

Callers

nothing calls this directly

Calls 7

TrackCreatedMethod · 0.95
GetAllFilesMethod · 0.95
StageAllFilesMethod · 0.95
RollbackCreatedFilesMethod · 0.95
runCommandInDirFunction · 0.85
NewFileTrackerFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected