test: Updates for fs/osutil package changes

This commit is contained in:
Jakob Borg 2017-11-05 10:05:18 +01:00
parent d7d45d8092
commit 72c5f2e5c6
6 changed files with 28 additions and 29 deletions

View File

@ -11,10 +11,9 @@ package integration
import ( import (
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"testing" "testing"
"time" "time"
"github.com/syncthing/syncthing/lib/osutil"
) )
func TestCLIReset(t *testing.T) { func TestCLIReset(t *testing.T) {
@ -50,7 +49,7 @@ func TestCLIReset(t *testing.T) {
// Clean up // Clean up
dirs, err = osutil.Glob("*.syncthing-reset-*") dirs, err = filepath.Glob("*.syncthing-reset-*")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -13,10 +13,10 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
"path/filepath"
"testing" "testing"
"time" "time"
"github.com/syncthing/syncthing/lib/osutil"
"github.com/syncthing/syncthing/lib/rc" "github.com/syncthing/syncthing/lib/rc"
) )
@ -127,7 +127,7 @@ func TestConflictsDefault(t *testing.T) {
// The conflict is expected on the s2 side due to how we calculate which // The conflict is expected on the s2 side due to how we calculate which
// file is the winner (based on device ID) // file is the winner (based on device ID)
files, err := osutil.Glob("s2/*sync-conflict*") files, err := filepath.Glob("s2/*sync-conflict*")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -177,7 +177,7 @@ func TestConflictsDefault(t *testing.T) {
// As such, we get the edited content synced back to s1 where it was // As such, we get the edited content synced back to s1 where it was
// removed. // removed.
files, err = osutil.Glob("s2/*sync-conflict*") files, err = filepath.Glob("s2/*sync-conflict*")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -253,7 +253,7 @@ func TestConflictsInitialMerge(t *testing.T) {
// s1 should have three-four files (there's a conflict from s2 which may or may not have synced yet) // s1 should have three-four files (there's a conflict from s2 which may or may not have synced yet)
files, err := osutil.Glob("s1/file*") files, err := filepath.Glob("s1/file*")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -263,7 +263,7 @@ func TestConflictsInitialMerge(t *testing.T) {
// s2 should have four files (there's a conflict) // s2 should have four files (there's a conflict)
files, err = osutil.Glob("s2/file*") files, err = filepath.Glob("s2/file*")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -273,7 +273,7 @@ func TestConflictsInitialMerge(t *testing.T) {
// file1 is in conflict, so there's two versions of that one // file1 is in conflict, so there's two versions of that one
files, err = osutil.Glob("s2/file1*") files, err = filepath.Glob("s2/file1*")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -328,7 +328,7 @@ func TestConflictsIndexReset(t *testing.T) {
// s1 should have three files // s1 should have three files
files, err := osutil.Glob("s1/file*") files, err := filepath.Glob("s1/file*")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -338,7 +338,7 @@ func TestConflictsIndexReset(t *testing.T) {
// s2 should have three // s2 should have three
files, err = osutil.Glob("s2/file*") files, err = filepath.Glob("s2/file*")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -402,7 +402,7 @@ func TestConflictsIndexReset(t *testing.T) {
// s2 should have five files (three plus two conflicts) // s2 should have five files (three plus two conflicts)
files, err = osutil.Glob("s2/file*") files, err = filepath.Glob("s2/file*")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -412,7 +412,7 @@ func TestConflictsIndexReset(t *testing.T) {
// file1 is in conflict, so there's two versions of that one // file1 is in conflict, so there's two versions of that one
files, err = osutil.Glob("s2/file1*") files, err = filepath.Glob("s2/file1*")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -422,7 +422,7 @@ func TestConflictsIndexReset(t *testing.T) {
// file2 is in conflict, so there's two versions of that one // file2 is in conflict, so there's two versions of that one
files, err = osutil.Glob("s2/file2*") files, err = filepath.Glob("s2/file2*")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -12,10 +12,10 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"log" "log"
"os"
"testing" "testing"
"github.com/syncthing/syncthing/lib/config" "github.com/syncthing/syncthing/lib/config"
"github.com/syncthing/syncthing/lib/osutil"
"github.com/syncthing/syncthing/lib/protocol" "github.com/syncthing/syncthing/lib/protocol"
"github.com/syncthing/syncthing/lib/rc" "github.com/syncthing/syncthing/lib/rc"
) )
@ -54,8 +54,8 @@ func TestManyPeers(t *testing.T) {
cfg.Folders[0].Devices = append(cfg.Folders[0].Devices, config.FolderDeviceConfiguration{DeviceID: id}) cfg.Folders[0].Devices = append(cfg.Folders[0].Devices, config.FolderDeviceConfiguration{DeviceID: id})
} }
osutil.Rename("h2/config.xml", "h2/config.xml.orig") os.Rename("h2/config.xml", "h2/config.xml.orig")
defer osutil.Rename("h2/config.xml.orig", "h2/config.xml") defer os.Rename("h2/config.xml.orig", "h2/config.xml")
var buf bytes.Buffer var buf bytes.Buffer
json.NewEncoder(&buf).Encode(cfg) json.NewEncoder(&buf).Encode(cfg)

View File

@ -13,8 +13,9 @@ import (
"os" "os"
"testing" "testing"
"github.com/syncthing/syncthing/lib/fs"
"github.com/syncthing/syncthing/lib/config" "github.com/syncthing/syncthing/lib/config"
"github.com/syncthing/syncthing/lib/osutil"
"github.com/syncthing/syncthing/lib/protocol" "github.com/syncthing/syncthing/lib/protocol"
"github.com/syncthing/syncthing/lib/rc" "github.com/syncthing/syncthing/lib/rc"
) )
@ -51,7 +52,7 @@ func TestAddDeviceWithoutRestart(t *testing.T) {
os.Remove("h4/config.xml.orig") os.Remove("h4/config.xml.orig")
os.Rename("h4/config.xml", "h4/config.xml.orig") os.Rename("h4/config.xml", "h4/config.xml.orig")
defer osutil.Rename("h4/config.xml.orig", "h4/config.xml") defer os.Rename("h4/config.xml.orig", "h4/config.xml")
cfg, err := p4.GetConfig() cfg, err := p4.GetConfig()
if err != nil { if err != nil {
@ -118,7 +119,7 @@ func TestFolderWithoutRestart(t *testing.T) {
os.Remove("h1/config.xml.orig") os.Remove("h1/config.xml.orig")
os.Rename("h1/config.xml", "h1/config.xml.orig") os.Rename("h1/config.xml", "h1/config.xml.orig")
defer osutil.Rename("h1/config.xml.orig", "h1/config.xml") defer os.Rename("h1/config.xml.orig", "h1/config.xml")
cfg, err := p1.GetConfig() cfg, err := p1.GetConfig()
if err != nil { if err != nil {
@ -127,7 +128,8 @@ func TestFolderWithoutRestart(t *testing.T) {
newFolder := config.FolderConfiguration{ newFolder := config.FolderConfiguration{
ID: "testfolder", ID: "testfolder",
RawPath: "testfolder-p1", FilesystemType: fs.FilesystemTypeBasic,
Path: "testfolder-p1",
RescanIntervalS: 86400, RescanIntervalS: 86400,
Copiers: 1, Copiers: 1,
Hashers: 1, Hashers: 1,
@ -155,14 +157,14 @@ func TestFolderWithoutRestart(t *testing.T) {
os.Remove("h4/config.xml.orig") os.Remove("h4/config.xml.orig")
os.Rename("h4/config.xml", "h4/config.xml.orig") os.Rename("h4/config.xml", "h4/config.xml.orig")
defer osutil.Rename("h4/config.xml.orig", "h4/config.xml") defer os.Rename("h4/config.xml.orig", "h4/config.xml")
cfg, err = p4.GetConfig() cfg, err = p4.GetConfig()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
newFolder.RawPath = "testfolder-p4" newFolder.Path = "testfolder-p4"
newFolder.Devices = []config.FolderDeviceConfiguration{{DeviceID: p1.ID()}} newFolder.Devices = []config.FolderDeviceConfiguration{{DeviceID: p1.ID()}}
newDevice.DeviceID = p1.ID() newDevice.DeviceID = p1.ID()
newDevice.Name = "p1" newDevice.Name = "p1"

View File

@ -17,7 +17,6 @@ import (
"time" "time"
"github.com/syncthing/syncthing/lib/config" "github.com/syncthing/syncthing/lib/config"
"github.com/syncthing/syncthing/lib/osutil"
"github.com/syncthing/syncthing/lib/protocol" "github.com/syncthing/syncthing/lib/protocol"
"github.com/syncthing/syncthing/lib/rc" "github.com/syncthing/syncthing/lib/rc"
) )
@ -30,7 +29,7 @@ func TestOverride(t *testing.T) {
fld.Type = config.FolderTypeSendOnly fld.Type = config.FolderTypeSendOnly
cfg.SetFolder(fld) cfg.SetFolder(fld)
os.Rename("h1/config.xml", "h1/config.xml.orig") os.Rename("h1/config.xml", "h1/config.xml.orig")
defer osutil.Rename("h1/config.xml.orig", "h1/config.xml") defer os.Rename("h1/config.xml.orig", "h1/config.xml")
cfg.Save() cfg.Save()
log.Println("Cleaning...") log.Println("Cleaning...")
@ -159,7 +158,7 @@ func TestOverrideIgnores(t *testing.T) {
fld.ReadOnly = true fld.ReadOnly = true
cfg.SetFolder(fld) cfg.SetFolder(fld)
os.Rename("h1/config.xml", "h1/config.xml.orig") os.Rename("h1/config.xml", "h1/config.xml.orig")
defer osutil.Rename("h1/config.xml.orig", "h1/config.xml") defer os.Rename("h1/config.xml.orig", "h1/config.xml")
cfg.Save() cfg.Save()
log.Println("Cleaning...") log.Println("Cleaning...")

View File

@ -26,7 +26,6 @@ import (
"time" "time"
"unicode" "unicode"
"github.com/syncthing/syncthing/lib/osutil"
"github.com/syncthing/syncthing/lib/rc" "github.com/syncthing/syncthing/lib/rc"
) )
@ -188,7 +187,7 @@ func alterFiles(dir string) error {
} }
newPath := filepath.Join(filepath.Dir(path), string(base)) newPath := filepath.Join(filepath.Dir(path), string(base))
if newPath != path { if newPath != path {
return osutil.TryRename(path, newPath) return os.Rename(path, newPath)
} }
/* /*
@ -277,7 +276,7 @@ func (i *inifiteReader) Read(bs []byte) (int, error) {
// rm -rf // rm -rf
func removeAll(dirs ...string) error { func removeAll(dirs ...string) error {
for _, dir := range dirs { for _, dir := range dirs {
files, err := osutil.Glob(dir) files, err := filepath.Glob(dir)
if err != nil { if err != nil {
return err return err
} }