|
|
@@ -28,14 +28,9 @@ func TestRequestSimple(t *testing.T) {
|
|
|
// Verify that the model performs a request and creates a file based on
|
|
|
// an incoming index update.
|
|
|
|
|
|
- m, fc, fcfg, w := setupModelWithConnection()
|
|
|
+ m, fc, fcfg := setupModelWithConnection()
|
|
|
tfs := fcfg.Filesystem()
|
|
|
- defer func() {
|
|
|
- m.Stop()
|
|
|
- m.db.Close()
|
|
|
- os.RemoveAll(tfs.URI())
|
|
|
- os.Remove(w.ConfigPath())
|
|
|
- }()
|
|
|
+ defer cleanupModelAndRemoveDir(m, tfs.URI())
|
|
|
|
|
|
// We listen for incoming index updates and trigger when we see one for
|
|
|
// the expected test file.
|
|
|
@@ -76,13 +71,8 @@ func TestSymlinkTraversalRead(t *testing.T) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- m, fc, fcfg, w := setupModelWithConnection()
|
|
|
- defer func() {
|
|
|
- m.Stop()
|
|
|
- m.db.Close()
|
|
|
- os.RemoveAll(fcfg.Filesystem().URI())
|
|
|
- os.Remove(w.ConfigPath())
|
|
|
- }()
|
|
|
+ m, fc, fcfg := setupModelWithConnection()
|
|
|
+ defer cleanupModelAndRemoveDir(m, fcfg.Filesystem().URI())
|
|
|
|
|
|
// We listen for incoming index updates and trigger when we see one for
|
|
|
// the expected test file.
|
|
|
@@ -124,13 +114,8 @@ func TestSymlinkTraversalWrite(t *testing.T) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- m, fc, fcfg, w := setupModelWithConnection()
|
|
|
- defer func() {
|
|
|
- m.Stop()
|
|
|
- m.db.Close()
|
|
|
- os.RemoveAll(fcfg.Filesystem().URI())
|
|
|
- os.Remove(w.ConfigPath())
|
|
|
- }()
|
|
|
+ m, fc, fcfg := setupModelWithConnection()
|
|
|
+ defer cleanupModelAndRemoveDir(m, fcfg.Filesystem().URI())
|
|
|
|
|
|
// We listen for incoming index updates and trigger when we see one for
|
|
|
// the expected names.
|
|
|
@@ -188,13 +173,8 @@ func TestSymlinkTraversalWrite(t *testing.T) {
|
|
|
func TestRequestCreateTmpSymlink(t *testing.T) {
|
|
|
// Test that an update for a temporary file is invalidated
|
|
|
|
|
|
- m, fc, fcfg, w := setupModelWithConnection()
|
|
|
- defer func() {
|
|
|
- m.Stop()
|
|
|
- m.db.Close()
|
|
|
- os.RemoveAll(fcfg.Filesystem().URI())
|
|
|
- os.Remove(w.ConfigPath())
|
|
|
- }()
|
|
|
+ m, fc, fcfg := setupModelWithConnection()
|
|
|
+ defer cleanupModelAndRemoveDir(m, fcfg.Filesystem().URI())
|
|
|
|
|
|
// We listen for incoming index updates and trigger when we see one for
|
|
|
// the expected test file.
|
|
|
@@ -243,8 +223,7 @@ func TestRequestVersioningSymlinkAttack(t *testing.T) {
|
|
|
fcfg.Versioning = config.VersioningConfiguration{Type: "trashcan"}
|
|
|
w.SetFolder(fcfg)
|
|
|
m, fc := setupModelWithConnectionFromWrapper(w)
|
|
|
- defer m.db.Close()
|
|
|
- defer m.Stop()
|
|
|
+ defer cleanupModel(m)
|
|
|
|
|
|
// Create a temporary directory that we will use as target to see if
|
|
|
// we can escape to it
|
|
|
@@ -312,12 +291,7 @@ func pullInvalidIgnored(t *testing.T, ft config.FolderType) {
|
|
|
fcfg.Type = ft
|
|
|
w.SetFolder(fcfg)
|
|
|
m := setupModel(w)
|
|
|
- defer func() {
|
|
|
- m.Stop()
|
|
|
- m.db.Close()
|
|
|
- os.RemoveAll(fss.URI())
|
|
|
- os.Remove(w.ConfigPath())
|
|
|
- }()
|
|
|
+ defer cleanupModelAndRemoveDir(m, fss.URI())
|
|
|
|
|
|
m.RemoveFolder(fcfg)
|
|
|
m.AddFolder(fcfg)
|
|
|
@@ -437,13 +411,8 @@ func pullInvalidIgnored(t *testing.T, ft config.FolderType) {
|
|
|
}
|
|
|
|
|
|
func TestIssue4841(t *testing.T) {
|
|
|
- m, fc, fcfg, w := setupModelWithConnection()
|
|
|
- defer func() {
|
|
|
- m.Stop()
|
|
|
- m.db.Close()
|
|
|
- os.RemoveAll(fcfg.Filesystem().URI())
|
|
|
- os.Remove(w.ConfigPath())
|
|
|
- }()
|
|
|
+ m, fc, fcfg := setupModelWithConnection()
|
|
|
+ defer cleanupModelAndRemoveDir(m, fcfg.Filesystem().URI())
|
|
|
|
|
|
received := make(chan protocol.FileInfo)
|
|
|
fc.mut.Lock()
|
|
|
@@ -480,14 +449,9 @@ func TestIssue4841(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestRescanIfHaveInvalidContent(t *testing.T) {
|
|
|
- m, fc, fcfg, w := setupModelWithConnection()
|
|
|
+ m, fc, fcfg := setupModelWithConnection()
|
|
|
tmpDir := fcfg.Filesystem().URI()
|
|
|
- defer func() {
|
|
|
- m.Stop()
|
|
|
- m.db.Close()
|
|
|
- os.RemoveAll(tmpDir)
|
|
|
- os.Remove(w.ConfigPath())
|
|
|
- }()
|
|
|
+ defer cleanupModelAndRemoveDir(m, tmpDir)
|
|
|
|
|
|
payload := []byte("hello")
|
|
|
|
|
|
@@ -546,14 +510,9 @@ func TestRescanIfHaveInvalidContent(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestParentDeletion(t *testing.T) {
|
|
|
- m, fc, fcfg, w := setupModelWithConnection()
|
|
|
+ m, fc, fcfg := setupModelWithConnection()
|
|
|
testFs := fcfg.Filesystem()
|
|
|
- defer func() {
|
|
|
- m.Stop()
|
|
|
- m.db.Close()
|
|
|
- os.RemoveAll(testFs.URI())
|
|
|
- os.Remove(w.ConfigPath())
|
|
|
- }()
|
|
|
+ defer cleanupModelAndRemoveDir(m, testFs.URI())
|
|
|
|
|
|
parent := "foo"
|
|
|
child := filepath.Join(parent, "bar")
|
|
|
@@ -630,13 +589,8 @@ func TestRequestSymlinkWindows(t *testing.T) {
|
|
|
t.Skip("windows specific test")
|
|
|
}
|
|
|
|
|
|
- m, fc, fcfg, w := setupModelWithConnection()
|
|
|
- defer func() {
|
|
|
- m.Stop()
|
|
|
- m.db.Close()
|
|
|
- os.RemoveAll(fcfg.Filesystem().URI())
|
|
|
- os.Remove(w.ConfigPath())
|
|
|
- }()
|
|
|
+ m, fc, fcfg := setupModelWithConnection()
|
|
|
+ defer cleanupModelAndRemoveDir(m, fcfg.Filesystem().URI())
|
|
|
|
|
|
done := make(chan struct{})
|
|
|
fc.mut.Lock()
|
|
|
@@ -702,15 +656,10 @@ func equalContents(path string, contents []byte) error {
|
|
|
}
|
|
|
|
|
|
func TestRequestRemoteRenameChanged(t *testing.T) {
|
|
|
- m, fc, fcfg, w := setupModelWithConnection()
|
|
|
+ m, fc, fcfg := setupModelWithConnection()
|
|
|
tfs := fcfg.Filesystem()
|
|
|
tmpDir := tfs.URI()
|
|
|
- defer func() {
|
|
|
- m.Stop()
|
|
|
- m.db.Close()
|
|
|
- os.RemoveAll(tmpDir)
|
|
|
- os.Remove(w.ConfigPath())
|
|
|
- }()
|
|
|
+ defer cleanupModelAndRemoveDir(m, tfs.URI())
|
|
|
|
|
|
done := make(chan struct{})
|
|
|
fc.mut.Lock()
|
|
|
@@ -835,15 +784,10 @@ func TestRequestRemoteRenameChanged(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestRequestRemoteRenameConflict(t *testing.T) {
|
|
|
- m, fc, fcfg, w := setupModelWithConnection()
|
|
|
+ m, fc, fcfg := setupModelWithConnection()
|
|
|
tfs := fcfg.Filesystem()
|
|
|
tmpDir := tfs.URI()
|
|
|
- defer func() {
|
|
|
- m.Stop()
|
|
|
- m.db.Close()
|
|
|
- os.RemoveAll(tmpDir)
|
|
|
- os.Remove(w.ConfigPath())
|
|
|
- }()
|
|
|
+ defer cleanupModelAndRemoveDir(m, tmpDir)
|
|
|
|
|
|
recv := make(chan int)
|
|
|
fc.mut.Lock()
|
|
|
@@ -931,14 +875,9 @@ func TestRequestRemoteRenameConflict(t *testing.T) {
|
|
|
}
|
|
|
|
|
|
func TestRequestDeleteChanged(t *testing.T) {
|
|
|
- m, fc, fcfg, w := setupModelWithConnection()
|
|
|
+ m, fc, fcfg := setupModelWithConnection()
|
|
|
tfs := fcfg.Filesystem()
|
|
|
- defer func() {
|
|
|
- m.Stop()
|
|
|
- m.db.Close()
|
|
|
- os.RemoveAll(tfs.URI())
|
|
|
- os.Remove(w.ConfigPath())
|
|
|
- }()
|
|
|
+ defer cleanupModelAndRemoveDir(m, tfs.URI())
|
|
|
|
|
|
done := make(chan struct{})
|
|
|
fc.mut.Lock()
|