diff options
Diffstat (limited to 'lib/model/folder_recvonly_test.go')
-rw-r--r-- | lib/model/folder_recvonly_test.go | 37 |
1 files changed, 11 insertions, 26 deletions
diff --git a/lib/model/folder_recvonly_test.go b/lib/model/folder_recvonly_test.go index 9a48c78f23..740a31202c 100644 --- a/lib/model/folder_recvonly_test.go +++ b/lib/model/folder_recvonly_test.go @@ -37,9 +37,9 @@ func TestRecvOnlyRevertDeletes(t *testing.T) { for _, dir := range []string{".stfolder", "ignDir", "unknownDir"} { must(t, ffs.MkdirAll(dir, 0755)) } - must(t, writeFile(ffs, "ignDir/ignFile", []byte("hello\n"), 0644)) - must(t, writeFile(ffs, "unknownDir/unknownFile", []byte("hello\n"), 0644)) - must(t, writeFile(ffs, ".stignore", []byte("ignDir\n"), 0644)) + writeFilePerm(t, ffs, "ignDir/ignFile", []byte("hello\n"), 0644) + writeFilePerm(t, ffs, "unknownDir/unknownFile", []byte("hello\n"), 0644) + writeFilePerm(t, ffs, ".stignore", []byte("ignDir\n"), 0644) knownFiles := setupKnownFiles(t, ffs, []byte("hello\n")) @@ -151,7 +151,7 @@ func TestRecvOnlyRevertNeeds(t *testing.T) { // Update the file. newData := []byte("totally different data\n") - must(t, writeFile(ffs, "knownDir/knownFile", newData, 0644)) + writeFilePerm(t, ffs, "knownDir/knownFile", newData, 0644) // Rescan. @@ -241,8 +241,8 @@ func TestRecvOnlyUndoChanges(t *testing.T) { // Create a file and modify another const file = "foo" - must(t, writeFile(ffs, file, []byte("hello\n"), 0644)) - must(t, writeFile(ffs, "knownDir/knownFile", []byte("bye\n"), 0644)) + writeFilePerm(t, ffs, file, []byte("hello\n"), 0644) + writeFilePerm(t, ffs, "knownDir/knownFile", []byte("bye\n"), 0644) must(t, m.ScanFolder("ro")) @@ -254,7 +254,7 @@ func TestRecvOnlyUndoChanges(t *testing.T) { // Remove the file again and undo the modification must(t, ffs.Remove(file)) - must(t, writeFile(ffs, "knownDir/knownFile", oldData, 0644)) + writeFilePerm(t, ffs, "knownDir/knownFile", oldData, 0644) must(t, ffs.Chtimes("knownDir/knownFile", knownFiles[1].ModTime(), knownFiles[1].ModTime())) must(t, m.ScanFolder("ro")) @@ -377,8 +377,8 @@ func TestRecvOnlyRemoteUndoChanges(t *testing.T) { const file = "foo" knownFile := filepath.Join("knownDir", "knownFile") - must(t, writeFile(ffs, file, []byte("hello\n"), 0644)) - must(t, writeFile(ffs, knownFile, []byte("bye\n"), 0644)) + writeFilePerm(t, ffs, file, []byte("hello\n"), 0644) + writeFilePerm(t, ffs, knownFile, []byte("bye\n"), 0644) must(t, m.ScanFolder("ro")) @@ -434,7 +434,7 @@ func TestRecvOnlyRevertOwnID(t *testing.T) { must(t, ffs.MkdirAll(".stfolder", 0755)) data := []byte("hello\n") name := "foo" - must(t, writeFile(ffs, name, data, 0644)) + writeFilePerm(t, ffs, name, data, 0644) // Make sure the file is scanned and locally changed must(t, m.ScanFolder("ro")) @@ -484,7 +484,7 @@ func setupKnownFiles(t *testing.T, ffs fs.Filesystem, data []byte) []protocol.Fi t.Helper() must(t, ffs.MkdirAll("knownDir", 0755)) - must(t, writeFile(ffs, "knownDir/knownFile", data, 0644)) + writeFilePerm(t, ffs, "knownDir/knownFile", data, 0644) t0 := time.Now().Add(-1 * time.Minute) must(t, ffs.Chtimes("knownDir/knownFile", t0, t0)) @@ -541,18 +541,3 @@ func setupROFolder(t *testing.T) (*testModel, *receiveOnlyFolder, context.Cancel return m, f, cancel } - -func writeFile(fs fs.Filesystem, filename string, data []byte, perm fs.FileMode) error { - fd, err := fs.Create(filename) - if err != nil { - return err - } - _, err = fd.Write(data) - if err != nil { - return err - } - if err := fd.Close(); err != nil { - return err - } - return fs.Chmod(filename, perm) -} |