lib/model: Improve test utilities (#5584)
This commit is contained in:
committed by
Audrius Butkevicius
parent
3a75b63776
commit
b1564e53e4
@@ -94,10 +94,10 @@ func createFile(t *testing.T, name string, fs fs.Filesystem) protocol.FileInfo {
|
||||
return file
|
||||
}
|
||||
|
||||
func setupSendReceiveFolder(files ...protocol.FileInfo) (*model, *sendReceiveFolder, string) {
|
||||
func setupSendReceiveFolder(files ...protocol.FileInfo) (*model, *sendReceiveFolder) {
|
||||
w := createTmpWrapper(defaultCfg)
|
||||
model := newModel(w, myID, "syncthing", "dev", db.OpenMemory(), nil)
|
||||
fcfg, tmpDir := testFolderConfigTmp()
|
||||
fcfg := testFolderConfigTmp()
|
||||
model.AddFolder(fcfg)
|
||||
|
||||
// Update index
|
||||
@@ -123,7 +123,7 @@ func setupSendReceiveFolder(files ...protocol.FileInfo) (*model, *sendReceiveFol
|
||||
// Folders are never actually started, so no initial scan will be done
|
||||
close(f.initialScanFinished)
|
||||
|
||||
return model, f, tmpDir
|
||||
return model, f
|
||||
}
|
||||
|
||||
// Layout of the files: (indexes from the above array)
|
||||
@@ -141,10 +141,10 @@ func TestHandleFile(t *testing.T) {
|
||||
requiredFile := existingFile
|
||||
requiredFile.Blocks = blocks[1:]
|
||||
|
||||
m, f, tmpDir := setupSendReceiveFolder(existingFile)
|
||||
m, f := setupSendReceiveFolder(existingFile)
|
||||
defer func() {
|
||||
os.Remove(m.cfg.ConfigPath())
|
||||
os.Remove(tmpDir)
|
||||
os.Remove(f.Filesystem().URI())
|
||||
}()
|
||||
|
||||
copyChan := make(chan copyBlocksState, 1)
|
||||
@@ -187,10 +187,10 @@ func TestHandleFileWithTemp(t *testing.T) {
|
||||
requiredFile := existingFile
|
||||
requiredFile.Blocks = blocks[1:]
|
||||
|
||||
m, f, tmpDir := setupSendReceiveFolder(existingFile)
|
||||
m, f := setupSendReceiveFolder(existingFile)
|
||||
defer func() {
|
||||
os.Remove(m.cfg.ConfigPath())
|
||||
os.Remove(tmpDir)
|
||||
os.Remove(f.Filesystem().URI())
|
||||
}()
|
||||
|
||||
if _, err := prepareTmpFile(f.Filesystem()); err != nil {
|
||||
@@ -240,10 +240,10 @@ func TestCopierFinder(t *testing.T) {
|
||||
requiredFile.Blocks = blocks[1:]
|
||||
requiredFile.Name = "file2"
|
||||
|
||||
m, f, tmpDir := setupSendReceiveFolder(existingFile)
|
||||
m, f := setupSendReceiveFolder(existingFile)
|
||||
defer func() {
|
||||
os.Remove(m.cfg.ConfigPath())
|
||||
os.Remove(tmpDir)
|
||||
os.Remove(f.Filesystem().URI())
|
||||
}()
|
||||
|
||||
if _, err := prepareTmpFile(f.Filesystem()); err != nil {
|
||||
@@ -306,12 +306,12 @@ func TestCopierFinder(t *testing.T) {
|
||||
|
||||
func TestWeakHash(t *testing.T) {
|
||||
// Setup the model/pull environment
|
||||
model, fo, tmpDir := setupSendReceiveFolder()
|
||||
model, fo := setupSendReceiveFolder()
|
||||
ffs := fo.Filesystem()
|
||||
defer func() {
|
||||
os.Remove(model.cfg.ConfigPath())
|
||||
os.Remove(tmpDir)
|
||||
os.Remove(ffs.URI())
|
||||
}()
|
||||
ffs := fo.Filesystem()
|
||||
|
||||
tempFile := fs.TempName("weakhash")
|
||||
var shift int64 = 10
|
||||
@@ -438,10 +438,10 @@ func TestCopierCleanup(t *testing.T) {
|
||||
|
||||
// Create a file
|
||||
file := setupFile("test", []int{0})
|
||||
m, _, tmpDir := setupSendReceiveFolder(file)
|
||||
m, f := setupSendReceiveFolder(file)
|
||||
defer func() {
|
||||
os.Remove(m.cfg.ConfigPath())
|
||||
os.Remove(tmpDir)
|
||||
os.Remove(f.Filesystem().URI())
|
||||
}()
|
||||
|
||||
file.Blocks = []protocol.BlockInfo{blocks[1]}
|
||||
@@ -474,10 +474,10 @@ func TestCopierCleanup(t *testing.T) {
|
||||
func TestDeregisterOnFailInCopy(t *testing.T) {
|
||||
file := setupFile("filex", []int{0, 2, 0, 0, 5, 0, 0, 8})
|
||||
|
||||
m, f, tmpDir := setupSendReceiveFolder()
|
||||
m, f := setupSendReceiveFolder()
|
||||
defer func() {
|
||||
os.Remove(m.cfg.ConfigPath())
|
||||
os.Remove(tmpDir)
|
||||
os.Remove(f.Filesystem().URI())
|
||||
}()
|
||||
|
||||
// Set up our evet subscription early
|
||||
@@ -564,10 +564,10 @@ func TestDeregisterOnFailInCopy(t *testing.T) {
|
||||
func TestDeregisterOnFailInPull(t *testing.T) {
|
||||
file := setupFile("filex", []int{0, 2, 0, 0, 5, 0, 0, 8})
|
||||
|
||||
m, f, tmpDir := setupSendReceiveFolder()
|
||||
m, f := setupSendReceiveFolder()
|
||||
defer func() {
|
||||
os.Remove(m.cfg.ConfigPath())
|
||||
os.Remove(tmpDir)
|
||||
os.Remove(f.Filesystem().URI())
|
||||
}()
|
||||
|
||||
// Set up our evet subscription early
|
||||
@@ -642,14 +642,14 @@ func TestDeregisterOnFailInPull(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIssue3164(t *testing.T) {
|
||||
m, f, tmpDir := setupSendReceiveFolder()
|
||||
m, f := setupSendReceiveFolder()
|
||||
ffs := f.Filesystem()
|
||||
tmpDir := ffs.URI()
|
||||
defer func() {
|
||||
os.Remove(m.cfg.ConfigPath())
|
||||
os.Remove(tmpDir)
|
||||
}()
|
||||
|
||||
ffs := f.Filesystem()
|
||||
|
||||
ignDir := filepath.Join("issue3164", "oktodelete")
|
||||
subDir := filepath.Join(ignDir, "foobar")
|
||||
if err := ffs.MkdirAll(subDir, 0777); err != nil {
|
||||
@@ -741,14 +741,14 @@ func TestDiffEmpty(t *testing.T) {
|
||||
// option is true and the permissions do not match between the file on disk and
|
||||
// in the db.
|
||||
func TestDeleteIgnorePerms(t *testing.T) {
|
||||
m, f, tmpDir := setupSendReceiveFolder()
|
||||
m, f := setupSendReceiveFolder()
|
||||
ffs := f.Filesystem()
|
||||
defer func() {
|
||||
os.Remove(m.cfg.ConfigPath())
|
||||
os.Remove(tmpDir)
|
||||
os.Remove(ffs.URI())
|
||||
}()
|
||||
f.IgnorePerms = true
|
||||
|
||||
ffs := f.Filesystem()
|
||||
name := "deleteIgnorePerms"
|
||||
file, err := ffs.Create(name)
|
||||
if err != nil {
|
||||
@@ -797,7 +797,7 @@ func TestCopyOwner(t *testing.T) {
|
||||
// Set up a folder with the CopyParentOwner bit and backed by a fake
|
||||
// filesystem.
|
||||
|
||||
m, f, _ := setupSendReceiveFolder()
|
||||
m, f := setupSendReceiveFolder()
|
||||
defer os.Remove(m.cfg.ConfigPath())
|
||||
f.folder.FolderConfiguration = config.NewFolderConfiguration(m.id, f.ID, f.Label, fs.FilesystemTypeFake, "/TestCopyOwner")
|
||||
f.folder.FolderConfiguration.CopyOwnershipFromParent = true
|
||||
@@ -886,13 +886,13 @@ func TestCopyOwner(t *testing.T) {
|
||||
// TestSRConflictReplaceFileByDir checks that a conflict is created when an existing file
|
||||
// is replaced with a directory and versions are conflicting
|
||||
func TestSRConflictReplaceFileByDir(t *testing.T) {
|
||||
m, f, tmpDir := setupSendReceiveFolder()
|
||||
m, f := setupSendReceiveFolder()
|
||||
ffs := f.Filesystem()
|
||||
defer func() {
|
||||
os.Remove(m.cfg.ConfigPath())
|
||||
os.Remove(tmpDir)
|
||||
os.Remove(ffs.URI())
|
||||
}()
|
||||
|
||||
ffs := f.Filesystem()
|
||||
name := "foo"
|
||||
|
||||
// create local file
|
||||
@@ -921,13 +921,13 @@ func TestSRConflictReplaceFileByDir(t *testing.T) {
|
||||
// TestSRConflictReplaceFileByLink checks that a conflict is created when an existing file
|
||||
// is replaced with a link and versions are conflicting
|
||||
func TestSRConflictReplaceFileByLink(t *testing.T) {
|
||||
m, f, tmpDir := setupSendReceiveFolder()
|
||||
m, f := setupSendReceiveFolder()
|
||||
ffs := f.Filesystem()
|
||||
defer func() {
|
||||
os.Remove(m.cfg.ConfigPath())
|
||||
os.Remove(tmpDir)
|
||||
os.Remove(ffs.URI())
|
||||
}()
|
||||
|
||||
ffs := f.Filesystem()
|
||||
name := "foo"
|
||||
|
||||
// create local file
|
||||
|
||||
Reference in New Issue
Block a user