windows: make tests work properly

This commit is contained in:
Nick Craig-Wood 2015-02-07 15:52:06 +00:00
parent 20ad96f3cd
commit b4e19cfd62
2 changed files with 26 additions and 20 deletions

View File

@ -10,6 +10,7 @@ import (
"log" "log"
"os" "os"
"path" "path"
"path/filepath"
"regexp" "regexp"
"strings" "strings"
"testing" "testing"
@ -74,6 +75,7 @@ func TestInit(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Failed to create temp dir: %v", err) t.Fatalf("Failed to create temp dir: %v", err)
} }
localName = filepath.ToSlash(localName)
t.Logf("Testing with local %q", localName) t.Logf("Testing with local %q", localName)
flocal, err = fs.NewFs(localName) flocal, err = fs.NewFs(localName)
if err != nil { if err != nil {
@ -83,6 +85,7 @@ func TestInit(t *testing.T) {
} }
func TestCalculateModifyWindow(t *testing.T) { func TestCalculateModifyWindow(t *testing.T) {
fs.CalculateModifyWindow(fremote, flocal) fs.CalculateModifyWindow(fremote, flocal)
t.Logf("ModifyWindow is %q", fs.Config.ModifyWindow)
} }
func TestMkdir(t *testing.T) { func TestMkdir(t *testing.T) {
@ -104,8 +107,8 @@ func TestCopyWithDryRun(t *testing.T) {
{Path: "sub dir/hello world", Size: 11, ModTime: t1, Md5sum: "5eb63bbbe01eeed093cb22bb8f5acdc3"}, {Path: "sub dir/hello world", Size: 11, ModTime: t1, Md5sum: "5eb63bbbe01eeed093cb22bb8f5acdc3"},
} }
fstest.CheckListing(t, flocal, items) fstest.CheckListingWithPrecision(t, flocal, items, fs.Config.ModifyWindow)
fstest.CheckListing(t, fremote, []fstest.Item{}) fstest.CheckListingWithPrecision(t, fremote, []fstest.Item{}, fs.Config.ModifyWindow)
} }
// Now without dry run // Now without dry run
@ -119,8 +122,8 @@ func TestCopy(t *testing.T) {
{Path: "sub dir/hello world", Size: 11, ModTime: t1, Md5sum: "5eb63bbbe01eeed093cb22bb8f5acdc3"}, {Path: "sub dir/hello world", Size: 11, ModTime: t1, Md5sum: "5eb63bbbe01eeed093cb22bb8f5acdc3"},
} }
fstest.CheckListing(t, flocal, items) fstest.CheckListingWithPrecision(t, flocal, items, fs.Config.ModifyWindow)
fstest.CheckListing(t, fremote, items) fstest.CheckListingWithPrecision(t, fremote, items, fs.Config.ModifyWindow)
} }
func TestLsd(t *testing.T) { func TestLsd(t *testing.T) {
@ -145,8 +148,8 @@ func TestCopyAfterDelete(t *testing.T) {
items := []fstest.Item{ items := []fstest.Item{
{Path: "sub dir/hello world", Size: 11, ModTime: t1, Md5sum: "5eb63bbbe01eeed093cb22bb8f5acdc3"}, {Path: "sub dir/hello world", Size: 11, ModTime: t1, Md5sum: "5eb63bbbe01eeed093cb22bb8f5acdc3"},
} }
fstest.CheckListing(t, flocal, []fstest.Item{}) fstest.CheckListingWithPrecision(t, flocal, []fstest.Item{}, fs.Config.ModifyWindow)
fstest.CheckListing(t, fremote, items) fstest.CheckListingWithPrecision(t, fremote, items, fs.Config.ModifyWindow)
} }
func TestCopyRedownload(t *testing.T) { func TestCopyRedownload(t *testing.T) {
@ -158,8 +161,8 @@ func TestCopyRedownload(t *testing.T) {
items := []fstest.Item{ items := []fstest.Item{
{Path: "sub dir/hello world", Size: 11, ModTime: t1, Md5sum: "5eb63bbbe01eeed093cb22bb8f5acdc3"}, {Path: "sub dir/hello world", Size: 11, ModTime: t1, Md5sum: "5eb63bbbe01eeed093cb22bb8f5acdc3"},
} }
fstest.CheckListingWithPrecision(t, flocal, items, fremote.Precision()) fstest.CheckListingWithPrecision(t, flocal, items, fs.Config.ModifyWindow)
fstest.CheckListing(t, fremote, items) fstest.CheckListingWithPrecision(t, fremote, items, fs.Config.ModifyWindow)
// Clean the directory // Clean the directory
cleanTempDir(t) cleanTempDir(t)
@ -179,8 +182,8 @@ func TestSyncAfterChangingModtimeOnly(t *testing.T) {
items := []fstest.Item{ items := []fstest.Item{
{Path: "empty space", Size: 0, ModTime: t2, Md5sum: "d41d8cd98f00b204e9800998ecf8427e"}, {Path: "empty space", Size: 0, ModTime: t2, Md5sum: "d41d8cd98f00b204e9800998ecf8427e"},
} }
fstest.CheckListing(t, flocal, items) fstest.CheckListingWithPrecision(t, flocal, items, fs.Config.ModifyWindow)
fstest.CheckListing(t, fremote, items) fstest.CheckListingWithPrecision(t, fremote, items, fs.Config.ModifyWindow)
} }
func TestSyncAfterAddingAFile(t *testing.T) { func TestSyncAfterAddingAFile(t *testing.T) {
@ -193,8 +196,8 @@ func TestSyncAfterAddingAFile(t *testing.T) {
{Path: "empty space", Size: 0, ModTime: t2, Md5sum: "d41d8cd98f00b204e9800998ecf8427e"}, {Path: "empty space", Size: 0, ModTime: t2, Md5sum: "d41d8cd98f00b204e9800998ecf8427e"},
{Path: "potato", Size: 60, ModTime: t3, Md5sum: "d6548b156ea68a4e003e786df99eee76"}, {Path: "potato", Size: 60, ModTime: t3, Md5sum: "d6548b156ea68a4e003e786df99eee76"},
} }
fstest.CheckListing(t, flocal, items) fstest.CheckListingWithPrecision(t, flocal, items, fs.Config.ModifyWindow)
fstest.CheckListing(t, fremote, items) fstest.CheckListingWithPrecision(t, fremote, items, fs.Config.ModifyWindow)
} }
func TestSyncAfterChangingFilesSizeOnly(t *testing.T) { func TestSyncAfterChangingFilesSizeOnly(t *testing.T) {
@ -207,8 +210,8 @@ func TestSyncAfterChangingFilesSizeOnly(t *testing.T) {
{Path: "empty space", Size: 0, ModTime: t2, Md5sum: "d41d8cd98f00b204e9800998ecf8427e"}, {Path: "empty space", Size: 0, ModTime: t2, Md5sum: "d41d8cd98f00b204e9800998ecf8427e"},
{Path: "potato", Size: 21, ModTime: t3, Md5sum: "100defcf18c42a1e0dc42a789b107cd2"}, {Path: "potato", Size: 21, ModTime: t3, Md5sum: "100defcf18c42a1e0dc42a789b107cd2"},
} }
fstest.CheckListing(t, flocal, items) fstest.CheckListingWithPrecision(t, flocal, items, fs.Config.ModifyWindow)
fstest.CheckListing(t, fremote, items) fstest.CheckListingWithPrecision(t, fremote, items, fs.Config.ModifyWindow)
} }
// Sync after changing a file's contents, modtime but not length // Sync after changing a file's contents, modtime but not length
@ -222,8 +225,8 @@ func TestSyncAfterChangingContentsOnly(t *testing.T) {
{Path: "empty space", Size: 0, ModTime: t2, Md5sum: "d41d8cd98f00b204e9800998ecf8427e"}, {Path: "empty space", Size: 0, ModTime: t2, Md5sum: "d41d8cd98f00b204e9800998ecf8427e"},
{Path: "potato", Size: 21, ModTime: t2, Md5sum: "e4cb6955d9106df6263c45fcfc10f163"}, {Path: "potato", Size: 21, ModTime: t2, Md5sum: "e4cb6955d9106df6263c45fcfc10f163"},
} }
fstest.CheckListing(t, flocal, items) fstest.CheckListingWithPrecision(t, flocal, items, fs.Config.ModifyWindow)
fstest.CheckListing(t, fremote, items) fstest.CheckListingWithPrecision(t, fremote, items, fs.Config.ModifyWindow)
} }
// Sync after removing a file and adding a file --dry-run // Sync after removing a file and adding a file --dry-run
@ -248,8 +251,8 @@ func TestSyncAfterRemovingAFileAndAddingAFileDryRun(t *testing.T) {
{Path: "empty space", Size: 0, ModTime: t2, Md5sum: "d41d8cd98f00b204e9800998ecf8427e"}, {Path: "empty space", Size: 0, ModTime: t2, Md5sum: "d41d8cd98f00b204e9800998ecf8427e"},
{Path: "potato2", Size: 60, ModTime: t1, Md5sum: "d6548b156ea68a4e003e786df99eee76"}, {Path: "potato2", Size: 60, ModTime: t1, Md5sum: "d6548b156ea68a4e003e786df99eee76"},
} }
fstest.CheckListing(t, flocal, items) fstest.CheckListingWithPrecision(t, flocal, items, fs.Config.ModifyWindow)
fstest.CheckListing(t, fremote, before) fstest.CheckListingWithPrecision(t, fremote, before, fs.Config.ModifyWindow)
} }
// Sync after removing a file and adding a file // Sync after removing a file and adding a file
@ -262,8 +265,8 @@ func TestSyncAfterRemovingAFileAndAddingAFile(t *testing.T) {
{Path: "empty space", Size: 0, ModTime: t2, Md5sum: "d41d8cd98f00b204e9800998ecf8427e"}, {Path: "empty space", Size: 0, ModTime: t2, Md5sum: "d41d8cd98f00b204e9800998ecf8427e"},
{Path: "potato2", Size: 60, ModTime: t1, Md5sum: "d6548b156ea68a4e003e786df99eee76"}, {Path: "potato2", Size: 60, ModTime: t1, Md5sum: "d6548b156ea68a4e003e786df99eee76"},
} }
fstest.CheckListing(t, flocal, items) fstest.CheckListingWithPrecision(t, flocal, items, fs.Config.ModifyWindow)
fstest.CheckListing(t, fremote, items) fstest.CheckListingWithPrecision(t, fremote, items, fs.Config.ModifyWindow)
} }
func TestLs(t *testing.T) { func TestLs(t *testing.T) {

View File

@ -9,6 +9,7 @@ import (
"log" "log"
"math/rand" "math/rand"
"os" "os"
"path/filepath"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -80,6 +81,7 @@ func (is *Items) Find(t *testing.T, obj fs.Object, precision time.Duration) {
i, ok := is.byName[obj.Remote()] i, ok := is.byName[obj.Remote()]
if !ok { if !ok {
t.Errorf("Unexpected file %q", obj.Remote()) t.Errorf("Unexpected file %q", obj.Remote())
return
} }
delete(is.byName, obj.Remote()) delete(is.byName, obj.Remote())
i.Check(t, obj, precision) i.Check(t, obj, precision)
@ -140,6 +142,7 @@ func LocalRemote() (path string, err error) {
// Now remove the directory // Now remove the directory
err = os.Remove(path) err = os.Remove(path)
} }
path = filepath.ToSlash(path)
return return
} }