| 13 | ) |
| 14 | |
| 15 | func TestNoopWatcher(t *testing.T) { |
| 16 | t.Parallel() |
| 17 | |
| 18 | // Create the noop watcher under test. |
| 19 | wut := watcher.NewNoop() |
| 20 | |
| 21 | // Test adding/removing files (should have no effect). |
| 22 | err := wut.Add("some-file.txt") |
| 23 | assert.NoError(t, err, "noop watcher should not return error on Add") |
| 24 | |
| 25 | err = wut.Remove("some-file.txt") |
| 26 | assert.NoError(t, err, "noop watcher should not return error on Remove") |
| 27 | |
| 28 | ctx, cancel := context.WithCancel(t.Context()) |
| 29 | defer cancel() |
| 30 | |
| 31 | // Start a goroutine to wait for Next to return. |
| 32 | errC := make(chan error, 1) |
| 33 | go func() { |
| 34 | _, err := wut.Next(ctx) |
| 35 | errC <- err |
| 36 | }() |
| 37 | |
| 38 | select { |
| 39 | case <-errC: |
| 40 | require.Fail(t, "want Next to block") |
| 41 | default: |
| 42 | } |
| 43 | |
| 44 | // Cancel the context and check that Next returns. |
| 45 | cancel() |
| 46 | |
| 47 | select { |
| 48 | case err := <-errC: |
| 49 | assert.Error(t, err, "want Next error when context is canceled") |
| 50 | case <-time.After(testutil.WaitShort): |
| 51 | t.Fatal("want Next to return after context was canceled") |
| 52 | } |
| 53 | |
| 54 | // Test Close. |
| 55 | err = wut.Close() |
| 56 | assert.NoError(t, err, "want no error on Close") |
| 57 | } |
| 58 | |
| 59 | func TestNoopWatcher_CloseBeforeNext(t *testing.T) { |
| 60 | t.Parallel() |