mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-10 07:11:08 +00:00
209e68c1ba
Also adds idle time and keepalive parameters because how this is configured has changed in the new package version. The values are those that seems like might already be default, if keep-alives were enabled, which is not obvious from the doc comments. Also, Go 1.19 gofmt reformatting of comments.
77 lines
1.7 KiB
Go
77 lines
1.7 KiB
Go
// Copyright (C) 2017 The Syncthing Authors.
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
package versioner
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/d4l3k/messagediff"
|
|
)
|
|
|
|
// TestEmptyDirs models the following .stversions structure:
|
|
//
|
|
// .stversions/
|
|
// ├── keep1
|
|
// │ └── file1
|
|
// ├── keep2
|
|
// │ └── keep21
|
|
// │ └── keep22
|
|
// │ └── file1
|
|
// ├── remove1
|
|
// └── remove2
|
|
// └── remove21
|
|
// └── remove22
|
|
func TestEmptyDirs(t *testing.T) {
|
|
var paths = []struct {
|
|
path string
|
|
isFile bool
|
|
}{
|
|
{".", false},
|
|
{"keep1", false},
|
|
{"keep1/file1", true},
|
|
{"keep2", false},
|
|
{"keep2/keep21", false},
|
|
{"keep2/keep21/keep22", false},
|
|
{"keep2/keep21/keep22/file1", true},
|
|
{"remove1", false},
|
|
{"remove2", false},
|
|
{"remove2/remove21", false},
|
|
{"remove2/remove21/remove22", false},
|
|
}
|
|
|
|
var expected = []string{
|
|
"remove2/remove21/remove22",
|
|
"remove2/remove21",
|
|
"remove2",
|
|
"remove1",
|
|
}
|
|
|
|
// For compatibility with Windows
|
|
for i, p := range paths {
|
|
paths[i].path = filepath.FromSlash(p.path)
|
|
}
|
|
|
|
for i, p := range expected {
|
|
expected[i] = filepath.FromSlash(p)
|
|
}
|
|
|
|
dirTracker := make(emptyDirTracker)
|
|
for _, p := range paths {
|
|
if p.isFile {
|
|
dirTracker.addFile(p.path)
|
|
} else {
|
|
dirTracker.addDir(p.path)
|
|
}
|
|
}
|
|
|
|
result := dirTracker.emptyDirs()
|
|
if diff, equal := messagediff.PrettyDiff(expected, result); !equal {
|
|
t.Errorf("Incorrect empty directories list; got %v, expected %v\n%v", result, expected, diff)
|
|
}
|
|
}
|