MCPcopy
hub / github.com/syncthing/syncthing / TestRenameSequenceOrder

Function TestRenameSequenceOrder

lib/model/model_test.go:3240–3300  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3238}
3239
3240func TestRenameSequenceOrder(t *testing.T) {
3241 wcfg, fcfg := newDefaultCfgWrapper(t)
3242 m := setupModel(t, wcfg)
3243 defer cleanupModel(m)
3244
3245 numFiles := 20
3246
3247 ffs := fcfg.Filesystem()
3248 for i := 0; i < numFiles; i++ {
3249 v := fmt.Sprintf("%d", i)
3250 writeFile(t, ffs, v, []byte(v))
3251 }
3252
3253 m.ScanFolders()
3254
3255 count := countIterator[protocol.FileInfo](t)(m.LocalFiles("default", protocol.LocalDeviceID))
3256 if count != numFiles {
3257 t.Errorf("Unexpected count: %d != %d", count, numFiles)
3258 }
3259
3260 // Modify all the files, other than the ones we expect to rename
3261 for i := 0; i < numFiles; i++ {
3262 if i == 3 || i == 17 || i == 16 || i == 4 {
3263 continue
3264 }
3265 v := fmt.Sprintf("%d", i)
3266 writeFile(t, ffs, v, []byte(v+"-new"))
3267 }
3268 // Rename
3269 must(t, ffs.Rename("3", "17"))
3270 must(t, ffs.Rename("16", "4"))
3271
3272 // Scan
3273 m.ScanFolders()
3274
3275 var firstExpectedSequence int64
3276 var secondExpectedSequence int64
3277 failed := false
3278 it, errFn := m.LocalFilesSequenced("default", protocol.LocalDeviceID, 0)
3279 for i := range it {
3280 t.Log(i)
3281 if i.FileName() == "17" {
3282 firstExpectedSequence = i.SequenceNo() + 1
3283 }
3284 if i.FileName() == "4" {
3285 secondExpectedSequence = i.SequenceNo() + 1
3286 }
3287 if i.FileName() == "3" {
3288 failed = i.SequenceNo() != firstExpectedSequence || failed
3289 }
3290 if i.FileName() == "16" {
3291 failed = i.SequenceNo() != secondExpectedSequence || failed
3292 }
3293 }
3294 if err := errFn(); err != nil {
3295 t.Fatal(err)
3296 }
3297 if failed {

Callers

nothing calls this directly

Calls 14

newDefaultCfgWrapperFunction · 0.85
setupModelFunction · 0.85
cleanupModelFunction · 0.85
mustFunction · 0.85
FilesystemMethod · 0.80
FileNameMethod · 0.80
SequenceNoMethod · 0.80
FatalMethod · 0.80
writeFileFunction · 0.70
ScanFoldersMethod · 0.65
LocalFilesMethod · 0.65
RenameMethod · 0.65

Tested by

no test coverage detected