MCPcopy
hub / github.com/syncthing/syncthing / TestVersionRestore

Function TestVersionRestore

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

Source from the content-addressed store, hash-verified

2575}
2576
2577func TestVersionRestore(t *testing.T) {
2578 t.Skip("incompatible with fakefs")
2579
2580 // We create a bunch of files which we restore
2581 // In each file, we write the filename as the content
2582 // We verify that the content matches at the expected filenames
2583 // after the restore operation.
2584
2585 fcfg := newFolderConfiguration(defaultCfgWrapper, "default", "default", config.FilesystemTypeFake, srand.String(32))
2586 fcfg.Versioning.Type = "simple"
2587 fcfg.FSWatcherEnabled = false
2588 filesystem := fcfg.Filesystem()
2589
2590 rawConfig := config.Configuration{
2591 Version: config.CurrentVersion,
2592 Folders: []config.FolderConfiguration{fcfg},
2593 }
2594 cfg, cancel := newConfigWrapper(rawConfig)
2595 defer cancel()
2596
2597 m := setupModel(t, cfg)
2598 defer cleanupModel(m)
2599 m.ScanFolder("default")
2600
2601 sentinel, err := time.ParseInLocation(versioner.TimeFormat, "20180101-010101", time.Local)
2602 if err != nil {
2603 t.Fatal(err)
2604 }
2605
2606 for _, file := range []string{
2607 // Versions directory
2608 ".stversions/file~20171210-040404.txt", // will be restored
2609 ".stversions/existing~20171210-040404", // exists, should expect to be archived.
2610 ".stversions/something~20171210-040404", // will become directory, hence error
2611 ".stversions/dir/file~20171210-040404.txt",
2612 ".stversions/dir/file~20171210-040405.txt",
2613 ".stversions/dir/file~20171210-040406.txt",
2614 ".stversions/very/very/deep/one~20171210-040406.txt", // lives deep down, no directory exists.
2615 ".stversions/dir/existing~20171210-040406.txt", // exists, should expect to be archived.
2616 ".stversions/dir/cat", // untagged which was used by trashcan, supported
2617
2618 // "file.txt" will be restored
2619 "existing",
2620 "something/file", // Becomes directory
2621 "dir/file.txt",
2622 "dir/existing.txt",
2623 } {
2624 if build.IsWindows {
2625 file = filepath.FromSlash(file)
2626 }
2627 dir := filepath.Dir(file)
2628 must(t, filesystem.MkdirAll(dir, 0o755))
2629 if fd, err := filesystem.Create(file); err != nil {
2630 t.Fatal(err)
2631 } else if _, err := fd.Write([]byte(file)); err != nil {
2632 t.Fatal(err)
2633 } else if err := fd.Close(); err != nil {
2634 t.Fatal(err)

Callers

nothing calls this directly

Calls 15

TagFilenameFunction · 0.92
newFolderConfigurationFunction · 0.85
newConfigWrapperFunction · 0.85
setupModelFunction · 0.85
cleanupModelFunction · 0.85
mustFunction · 0.85
FilesystemMethod · 0.80
FatalMethod · 0.80
StringMethod · 0.65
ScanFolderMethod · 0.65
MkdirAllMethod · 0.65
CreateMethod · 0.65

Tested by

no test coverage detected