(t *testing.T)
| 199 | } |
| 200 | |
| 201 | func TestRecvOnlyUndoChanges(t *testing.T) { |
| 202 | // Get us a model up and running |
| 203 | |
| 204 | m, f, wcfgCancel := setupROFolder(t) |
| 205 | defer wcfgCancel() |
| 206 | ffs := f.Filesystem() |
| 207 | defer cleanupModel(m) |
| 208 | conn := addFakeConn(m, device1, f.ID) |
| 209 | |
| 210 | // Create some test data |
| 211 | |
| 212 | must(t, ffs.MkdirAll(".stfolder", 0o755)) |
| 213 | oldData := []byte("hello\n") |
| 214 | knownFiles := setupKnownFiles(t, ffs, oldData) |
| 215 | |
| 216 | // Send an index update for the known stuff |
| 217 | |
| 218 | must(t, m.Index(conn, &protocol.Index{Folder: "ro", Files: knownFiles})) |
| 219 | f.updateLocalsFromScanning(knownFiles) |
| 220 | |
| 221 | // Scan the folder. |
| 222 | |
| 223 | must(t, m.ScanFolder("ro")) |
| 224 | |
| 225 | // Everything should be in sync. |
| 226 | |
| 227 | size := mustV(m.GlobalSize("ro")) |
| 228 | if size.Files != 1 || size.Directories != 1 { |
| 229 | t.Fatalf("Global: expected 1 file and 1 directory: %+v", size) |
| 230 | } |
| 231 | size = mustV(m.LocalSize("ro", protocol.LocalDeviceID)) |
| 232 | if size.Files != 1 || size.Directories != 1 { |
| 233 | t.Fatalf("Local: expected 1 file and 1 directory: %+v", size) |
| 234 | } |
| 235 | size = mustV(m.NeedSize("ro", protocol.LocalDeviceID)) |
| 236 | if size.Files+size.Directories > 0 { |
| 237 | t.Fatalf("Need: expected nothing: %+v", size) |
| 238 | } |
| 239 | size = mustV(m.ReceiveOnlySize("ro")) |
| 240 | if size.Files+size.Directories > 0 { |
| 241 | t.Fatalf("ROChanged: expected nothing: %+v", size) |
| 242 | } |
| 243 | |
| 244 | // Create a file and modify another |
| 245 | |
| 246 | const file = "foo" |
| 247 | writeFilePerm(t, ffs, file, []byte("hello\n"), 0o644) |
| 248 | writeFilePerm(t, ffs, "knownDir/knownFile", []byte("bye\n"), 0o644) |
| 249 | |
| 250 | must(t, m.ScanFolder("ro")) |
| 251 | |
| 252 | size = mustV(m.ReceiveOnlySize("ro")) |
| 253 | if size.Files != 2 { |
| 254 | t.Fatalf("Receive only: expected 2 files: %+v", size) |
| 255 | } |
| 256 | |
| 257 | // Remove the file again and undo the modification |
| 258 |
nothing calls this directly
no test coverage detected