| 27 | } |
| 28 | |
| 29 | func TestWatcher(t *testing.T) { |
| 30 | watchedPaths := []string{".", "hello.txt", "watchedsubdir"} |
| 31 | testCases := []testCase{ |
| 32 | { |
| 33 | name: "Create text file", |
| 34 | expectedChanges: []string{"hello.txt"}, |
| 35 | changes: []testCaseChange{ |
| 36 | { |
| 37 | path: "hello.txt", |
| 38 | content: "hello", |
| 39 | }, |
| 40 | }, |
| 41 | }, |
| 42 | { |
| 43 | name: "Create file in folder", |
| 44 | expectedChanges: []string{"watchedsubdir"}, |
| 45 | changes: []testCaseChange{ |
| 46 | { |
| 47 | path: "watchedsubdir/unwatchedsubfile.txt", |
| 48 | content: "watchedsubdir", |
| 49 | }, |
| 50 | }, |
| 51 | }, |
| 52 | { |
| 53 | name: "Override file", |
| 54 | expectedChanges: []string{"hello.txt"}, |
| 55 | changes: []testCaseChange{ |
| 56 | { |
| 57 | path: "hello.txt", |
| 58 | content: "another hello", |
| 59 | }, |
| 60 | }, |
| 61 | }, |
| 62 | { |
| 63 | name: "Delete file", |
| 64 | expectedChanges: []string{}, |
| 65 | expectedDeletions: []string{"hello.txt"}, |
| 66 | changes: []testCaseChange{ |
| 67 | { |
| 68 | path: "hello.txt", |
| 69 | delete: true, |
| 70 | }, |
| 71 | }, |
| 72 | }, |
| 73 | } |
| 74 | |
| 75 | // Create TmpFolder |
| 76 | dir := t.TempDir() |
| 77 | |
| 78 | wdBackup, err := os.Getwd() |
| 79 | if err != nil { |
| 80 | t.Fatalf("Error getting current working directory: %v", err) |
| 81 | } |
| 82 | err = os.Chdir(dir) |
| 83 | if err != nil { |
| 84 | t.Fatalf("Error changing working directory: %v", err) |
| 85 | } |
| 86 | |