81bc3bab
refactor(watcher): use t.Context() and range over int in tests
a73x 2026-04-29 05:56
diff --git a/internal/watcher/watcher_test.go b/internal/watcher/watcher_test.go index f944057..325fddc 100644 --- a/internal/watcher/watcher_test.go +++ b/internal/watcher/watcher_test.go @@ -1,7 +1,6 @@ package watcher import ( "context" "os" "path/filepath" "testing" @@ -32,9 +31,7 @@ func TestWatcherFiresOnInPlaceWrite(t *testing.T) { } defer w.Close() ctx, cancel := context.WithCancel(context.Background()) defer cancel() if err := w.Start(ctx); err != nil { if err := w.Start(t.Context()); err != nil { t.Fatal(err) } @@ -66,9 +63,7 @@ func TestWatcherFiresOnAtomicSave(t *testing.T) { t.Fatal(err) } defer w.Close() ctx, cancel := context.WithCancel(context.Background()) defer cancel() if err := w.Start(ctx); err != nil { if err := w.Start(t.Context()); err != nil { t.Fatal(err) } time.Sleep(20 * time.Millisecond) @@ -103,15 +98,13 @@ func TestWatcherDebouncesBurst(t *testing.T) { t.Fatal(err) } defer w.Close() ctx, cancel := context.WithCancel(context.Background()) defer cancel() if err := w.Start(ctx); err != nil { if err := w.Start(t.Context()); err != nil { t.Fatal(err) } time.Sleep(50 * time.Millisecond) // Burst of writes within debounce window for i := 0; i < 5; i++ { for i := range 5 { os.WriteFile(p, []byte{'a' + byte(i)}, 0o644) time.Sleep(20 * time.Millisecond) } @@ -147,9 +140,7 @@ func TestWatcherSkipsIgnoredPaths(t *testing.T) { t.Fatal(err) } defer w.Close() ctx, cancel := context.WithCancel(context.Background()) defer cancel() if err := w.Start(ctx); err != nil { if err := w.Start(t.Context()); err != nil { t.Fatal(err) } time.Sleep(50 * time.Millisecond)