MCPcopy
hub / github.com/syncthing/syncthing / TestRecvOnlyRevertDeletes

Function TestRecvOnlyRevertDeletes

lib/model/folder_recvonly_test.go:24–106  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22)
23
24func TestRecvOnlyRevertDeletes(t *testing.T) {
25 // Make sure that we delete extraneous files and directories when we hit
26 // Revert.
27
28 // Get us a model up and running
29
30 m, f, wcfgCancel := setupROFolder(t)
31 defer wcfgCancel()
32 ffs := f.Filesystem()
33 defer cleanupModel(m)
34 conn := addFakeConn(m, device1, f.ID)
35
36 // Create some test data
37
38 for _, dir := range []string{".stfolder", "ignDir", "unknownDir"} {
39 must(t, ffs.MkdirAll(dir, 0o755))
40 }
41 writeFilePerm(t, ffs, "ignDir/ignFile", []byte("hello\n"), 0o644)
42 writeFilePerm(t, ffs, "unknownDir/unknownFile", []byte("hello\n"), 0o644)
43 writeFilePerm(t, ffs, ".stignore", []byte("ignDir\n"), 0o644)
44
45 knownFiles := setupKnownFiles(t, ffs, []byte("hello\n"))
46
47 // Send and index update for the known stuff
48
49 must(t, m.Index(conn, &protocol.Index{Folder: "ro", Files: knownFiles}))
50 if err := f.updateLocalsFromScanning(knownFiles); err != nil {
51 t.Fatal(err)
52 }
53
54 size := mustV(m.GlobalSize("ro"))
55 if size.Files != 1 || size.Directories != 1 {
56 t.Fatalf("Global: expected 1 file and 1 directory: %+v", size)
57 }
58
59 // Scan, should discover the other stuff in the folder
60
61 must(t, m.ScanFolder("ro"))
62
63 // We should now have two files and two directories, with global state unchanged.
64
65 size = mustV(m.GlobalSize("ro"))
66 if size.Files != 1 || size.Directories != 1 {
67 t.Fatalf("Global: expected 1 file and 1 directory: %+v", size)
68 }
69 size = mustV(m.LocalSize("ro", protocol.LocalDeviceID))
70 if size.Files != 2 || size.Directories != 2 {
71 t.Fatalf("Local: expected 2 files and 2 directories: %+v", size)
72 }
73 size = mustV(m.ReceiveOnlySize("ro"))
74 if size.Files+size.Directories == 0 {
75 t.Fatalf("ROChanged: expected something: %+v", size)
76 }
77
78 // Revert should delete the unknown stuff
79
80 m.Revert("ro")
81

Callers

nothing calls this directly

Calls 15

IsNotExistFunction · 0.92
setupROFolderFunction · 0.85
cleanupModelFunction · 0.85
addFakeConnFunction · 0.85
mustFunction · 0.85
writeFilePermFunction · 0.85
setupKnownFilesFunction · 0.85
mustVFunction · 0.85
FilesystemMethod · 0.80
FatalMethod · 0.80
MkdirAllMethod · 0.65

Tested by

no test coverage detected