(t *testing.T)
| 28 | const eventWait = 3 * time.Second |
| 29 | |
| 30 | func TestWatcherFiresOnGoFileWrite(t *testing.T) { |
| 31 | dir := t.TempDir() |
| 32 | w, err := NewWatcher(WatcherOptions{Root: dir, Debounce: 30 * time.Millisecond}) |
| 33 | if err != nil { |
| 34 | t.Fatalf("NewWatcher: %v", err) |
| 35 | } |
| 36 | defer w.Close() |
| 37 | time.Sleep(watcherWarmup) |
| 38 | |
| 39 | // Writing a fresh .go file in the watched dir fires a Create, which is |
| 40 | // delivered reliably on both inotify and kqueue. Seed-then-modify races |
| 41 | // with kqueue's file-level watch registration on macOS CI. |
| 42 | if err := os.WriteFile(filepath.Join(dir, "main.go"), []byte("package x\n"), 0o644); err != nil { |
| 43 | t.Fatalf("write: %v", err) |
| 44 | } |
| 45 | if !waitEvent(t, w.Events(), eventWait) { |
| 46 | t.Fatal("expected debounced event after .go write") |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | func TestWatcherIgnoresNonGoFiles(t *testing.T) { |
| 51 | dir := t.TempDir() |
nothing calls this directly
no test coverage detected