GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4545 LGTM: imsodin, calmh
This commit is contained in:
committed by
Jakob Borg
parent
429b3a0429
commit
95a65bf0d0
@@ -10,6 +10,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
@@ -20,6 +21,7 @@ import (
|
||||
|
||||
"github.com/d4l3k/messagediff"
|
||||
"github.com/syncthing/syncthing/lib/fs"
|
||||
"github.com/syncthing/syncthing/lib/osutil"
|
||||
"github.com/syncthing/syncthing/lib/protocol"
|
||||
)
|
||||
|
||||
@@ -430,6 +432,62 @@ func TestFolderPath(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFolderCheckPath(t *testing.T) {
|
||||
n, err := ioutil.TempDir("", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = os.MkdirAll(filepath.Join(n, "dir", ".stfolder"), os.FileMode(0777))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
testcases := []struct {
|
||||
path string
|
||||
err error
|
||||
}{
|
||||
{
|
||||
path: "",
|
||||
err: errMarkerMissing,
|
||||
},
|
||||
{
|
||||
path: "does not exist",
|
||||
err: errPathMissing,
|
||||
},
|
||||
{
|
||||
path: "dir",
|
||||
err: nil,
|
||||
},
|
||||
}
|
||||
|
||||
err = osutil.DebugSymlinkForTestsOnly(filepath.Join(n, "dir"), filepath.Join(n, "link"))
|
||||
if err == nil {
|
||||
t.Log("running with symlink check")
|
||||
testcases = append(testcases, struct {
|
||||
path string
|
||||
err error
|
||||
}{
|
||||
path: "link",
|
||||
err: nil,
|
||||
})
|
||||
} else if runtime.GOOS != "windows" {
|
||||
t.Log("running without symlink check")
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, testcase := range testcases {
|
||||
cfg := FolderConfiguration{
|
||||
Path: filepath.Join(n, testcase.path),
|
||||
MarkerName: DefaultMarkerName,
|
||||
}
|
||||
|
||||
if err := cfg.CheckPath(); testcase.err != err {
|
||||
t.Errorf("unexpected error in case %s: %s != %s", testcase.path, err, testcase.err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewSaveLoad(t *testing.T) {
|
||||
path := "testdata/temp.xml"
|
||||
os.Remove(path)
|
||||
|
||||
Reference in New Issue
Block a user