MCPcopy
hub / github.com/go-task/task / TestFileWatch

Function TestFileWatch

watch_test.go:22–82  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

20)
21
22func TestFileWatch(t *testing.T) {
23 t.Parallel()
24
25 const dir = "testdata/watch"
26 _ = os.RemoveAll(filepathext.SmartJoin(dir, ".task"))
27 _ = os.RemoveAll(filepathext.SmartJoin(dir, "src"))
28
29 expectedOutput := strings.TrimSpace(`
30task: Started watching for tasks: default
31task: [default] echo "Task running!"
32Task running!
33task: task "default" finished running
34task: [default] echo "Task running!"
35Task running!
36task: task "default" finished running
37 `)
38
39 var buff bytes.Buffer
40 e := task.NewExecutor(
41 task.WithDir(dir),
42 task.WithStdout(&buff),
43 task.WithStderr(&buff),
44 task.WithWatch(true),
45 )
46
47 require.NoError(t, e.Setup())
48 buff.Reset()
49
50 dirPath := filepathext.SmartJoin(dir, "src")
51 filePath := filepathext.SmartJoin(dirPath, "a")
52
53 err := os.MkdirAll(dirPath, 0o755)
54 require.NoError(t, err)
55
56 err = os.WriteFile(filePath, []byte("test"), 0o644)
57 require.NoError(t, err)
58
59 ctx, cancel := context.WithCancel(context.Background())
60
61 go func() {
62 for {
63 select {
64 case <-ctx.Done():
65 return
66 default:
67 err := e.Run(ctx, &task.Call{Task: "default"})
68 if err != nil {
69 panic(err)
70 }
71 }
72 }
73 }()
74
75 time.Sleep(200 * time.Millisecond)
76 err = os.WriteFile(filePath, []byte("test updated"), 0o644)
77 require.NoError(t, err)
78
79 time.Sleep(200 * time.Millisecond)

Callers

nothing calls this directly

Calls 4

SetupMethod · 0.95
RunMethod · 0.95
SmartJoinFunction · 0.92
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…