MCPcopy
hub / github.com/syncthing/syncthing / TestRequestSimple

Function TestRequestSimple

lib/model/requests_test.go:29–70  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27)
28
29func TestRequestSimple(t *testing.T) {
30 // Verify that the model performs a request and creates a file based on
31 // an incoming index update.
32
33 m, fc, fcfg := setupModelWithConnection(t)
34 tfs := fcfg.Filesystem()
35 defer cleanupModelAndRemoveDir(m, tfs.URI())
36
37 // We listen for incoming index updates and trigger when we see one for
38 // the expected test file.
39 done := make(chan struct{})
40 fc.setIndexFn(func(_ context.Context, folder string, fs []protocol.FileInfo) error {
41 select {
42 case <-done:
43 t.Error("More than one index update sent")
44 default:
45 }
46 for _, f := range fs {
47 if f.Name == "testfile" {
48 close(done)
49 return nil
50 }
51 }
52 return nil
53 })
54
55 // Send an update for the test file, wait for it to sync and be reported back.
56 contents := []byte("test file contents\n")
57 fc.addFile("testfile", 0o644, protocol.FileInfoTypeFile, contents)
58 fc.addFile("testfile", 0o644, protocol.FileInfoTypeFile, contents)
59 fc.sendIndexUpdate()
60 select {
61 case <-done:
62 case <-time.After(10 * time.Second):
63 t.Fatal("timed out")
64 }
65
66 // Verify the contents
67 if err := equalContents(tfs, "testfile", contents); err != nil {
68 t.Error("File did not sync correctly:", err)
69 }
70}
71
72func TestSymlinkTraversalRead(t *testing.T) {
73 // Verify that a symlink can not be traversed for reading.

Callers

nothing calls this directly

Calls 10

setupModelWithConnectionFunction · 0.85
cleanupModelAndRemoveDirFunction · 0.85
equalContentsFunction · 0.85
FilesystemMethod · 0.80
setIndexFnMethod · 0.80
sendIndexUpdateMethod · 0.80
FatalMethod · 0.80
URIMethod · 0.65
ErrorMethod · 0.65
addFileMethod · 0.45

Tested by

no test coverage detected