From bd3ce5d4a3425c2a4601904118ba4166e109b455 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Mon, 20 Jul 2015 21:02:38 +0200 Subject: [PATCH 1/2] Fix tests on freebsd --- Vagrantfile | 7 +++++++ cmd/restic/integration_helpers_test.go | 5 ++++- node_test.go | 12 ++++++++---- test/helpers.go | 2 +- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 964770a80..ae66663bb 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -7,6 +7,13 @@ def packages_freebsd return <<-EOF pkg install -y git pkg install -y curl + + echo 'fuse_load="YES"' >> /boot/loader.conf + echo 'vfs.usermount=1' >> /etc/sysctl.conf + + kldload fuse + sysctl vfs.usermount=1 + pw groupmod operator -M vagrant EOF end diff --git a/cmd/restic/integration_helpers_test.go b/cmd/restic/integration_helpers_test.go index 8f815a0fe..a981019f0 100644 --- a/cmd/restic/integration_helpers_test.go +++ b/cmd/restic/integration_helpers_test.go @@ -65,7 +65,10 @@ func (e *dirEntry) equals(other *dirEntry) bool { return false } - if runtime.GOOS != "darwin" { + switch runtime.GOOS { + case "darwin", "freebsd": + // Skip ModTime check on darwin and freebsd + default: if e.fi.ModTime() != other.fi.ModTime() { fmt.Fprintf(os.Stderr, "%v: ModTime does not match (%v != %v)\n", e.path, e.fi.ModTime(), other.fi.ModTime()) return false diff --git a/node_test.go b/node_test.go index fb1200be7..f6ba3dd98 100644 --- a/node_test.go +++ b/node_test.go @@ -153,17 +153,21 @@ func TestNodeRestoreAt(t *testing.T) { func AssertFsTimeEqual(t *testing.T, label string, nodeType string, t1 time.Time, t2 time.Time) { var equal bool - if runtime.GOOS == "darwin" { - // Go currently doesn't support setting timestamps of symbolic links on darwin - if nodeType == "symlink" { + // Go currently doesn't support setting timestamps of symbolic links on darwin and freebsd + if nodeType == "symlink" { + switch runtime.GOOS { + case "darwin", "freebsd": return } + } + switch runtime.GOOS { + case "darwin": // HFS+ timestamps don't support sub-second precision, // see https://en.wikipedia.org/wiki/Comparison_of_file_systems diff := int(t1.Sub(t2).Seconds()) equal = diff == 0 - } else { + default: equal = t1.Equal(t2) } diff --git a/test/helpers.go b/test/helpers.go index a9306cf3a..504b582ca 100644 --- a/test/helpers.go +++ b/test/helpers.go @@ -88,7 +88,7 @@ func RandomReader(seed, size int) *bytes.Reader { // SetupTarTestFixture extracts the tarFile to outputDir. func SetupTarTestFixture(t testing.TB, outputDir, tarFile string) { - err := System("sh", "-c", `(cd "$1" && tar xz) < "$2"`, + err := System("sh", "-c", `(cd "$1" && tar xzf - ) < "$2"`, "sh", outputDir, tarFile) OK(t, err) } From 258b6a77eed7985afb53a420577835afabe4d36b Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Mon, 20 Jul 2015 21:29:21 +0200 Subject: [PATCH 2/2] Refactor skipping symlink ModTime checks, add OpenBSD --- cmd/restic/integration_helpers_test.go | 27 ++++++++++++++++++-------- node_test.go | 4 ++-- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/cmd/restic/integration_helpers_test.go b/cmd/restic/integration_helpers_test.go index a981019f0..fe794ab1e 100644 --- a/cmd/restic/integration_helpers_test.go +++ b/cmd/restic/integration_helpers_test.go @@ -54,6 +54,22 @@ func walkDir(dir string) <-chan *dirEntry { return ch } +func isSymlink(fi os.FileInfo) bool { + mode := fi.Mode() & (os.ModeType | os.ModeCharDevice) + return mode == os.ModeSymlink +} + +func sameModTime(fi1, fi2 os.FileInfo) bool { + switch runtime.GOOS { + case "darwin", "freebsd", "openbsd": + if isSymlink(fi1) && isSymlink(fi2) { + return true + } + } + + return fi1.ModTime() == fi2.ModTime() +} + func (e *dirEntry) equals(other *dirEntry) bool { if e.path != other.path { fmt.Fprintf(os.Stderr, "%v: path does not match (%v != %v)\n", e.path, e.path, other.path) @@ -65,14 +81,9 @@ func (e *dirEntry) equals(other *dirEntry) bool { return false } - switch runtime.GOOS { - case "darwin", "freebsd": - // Skip ModTime check on darwin and freebsd - default: - if e.fi.ModTime() != other.fi.ModTime() { - fmt.Fprintf(os.Stderr, "%v: ModTime does not match (%v != %v)\n", e.path, e.fi.ModTime(), other.fi.ModTime()) - return false - } + if !sameModTime(e.fi, other.fi) { + fmt.Fprintf(os.Stderr, "%v: ModTime does not match (%v != %v)\n", e.path, e.fi.ModTime(), other.fi.ModTime()) + return false } stat, _ := e.fi.Sys().(*syscall.Stat_t) diff --git a/node_test.go b/node_test.go index f6ba3dd98..f6104b49b 100644 --- a/node_test.go +++ b/node_test.go @@ -153,10 +153,10 @@ func TestNodeRestoreAt(t *testing.T) { func AssertFsTimeEqual(t *testing.T, label string, nodeType string, t1 time.Time, t2 time.Time) { var equal bool - // Go currently doesn't support setting timestamps of symbolic links on darwin and freebsd + // Go currently doesn't support setting timestamps of symbolic links on darwin and bsd if nodeType == "symlink" { switch runtime.GOOS { - case "darwin", "freebsd": + case "darwin", "freebsd", "openbsd": return } }