MCPcopy
hub / github.com/cloudflare/cloudflared / TestFileChanged

Function TestFileChanged

watcher/file_test.go:25–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23}
24
25func TestFileChanged(t *testing.T) {
26 filePath := "test_file"
27 f, err := os.Create(filePath)
28 assert.NoError(t, err)
29 defer func() {
30 f.Close()
31 os.Remove(filePath)
32 }()
33
34 service, err := NewFile()
35 assert.NoError(t, err)
36
37 err = service.Add(filePath)
38 assert.NoError(t, err)
39
40 n := &mockNotifier{}
41 go service.Start(n)
42
43 f.Sync()
44
45 w := bufio.NewWriter(f)
46 _, err = w.WriteString("hello Austin, do you like my file watcher?\n")
47 assert.NoError(t, err)
48 err = w.Flush()
49 assert.NoError(t, err)
50
51 // give it time to trigger
52 time.Sleep(20 * time.Millisecond)
53 service.Shutdown()
54
55 assert.Equal(t, filePath, n.eventPath, "notifier didn't get an new file write event")
56}

Callers

nothing calls this directly

Calls 9

AddMethod · 0.95
StartMethod · 0.95
ShutdownMethod · 0.95
NewFileFunction · 0.85
WriteStringMethod · 0.80
CloseMethod · 0.65
RemoveMethod · 0.65
EqualMethod · 0.65
FlushMethod · 0.45

Tested by

no test coverage detected