MCPcopy Create free account
hub / github.com/coder/coder / TestNoopWatcher

Function TestNoopWatcher

agent/agentcontainers/watcher/noop_test.go:15–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func 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
59func TestNoopWatcher_CloseBeforeNext(t *testing.T) {
60 t.Parallel()

Callers

nothing calls this directly

Calls 9

NewNoopFunction · 0.92
FatalMethod · 0.80
AddMethod · 0.65
RemoveMethod · 0.65
ContextMethod · 0.65
NextMethod · 0.65
CloseMethod · 0.65
FailMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected