Skip to content

Commit

Permalink
fuse: add unit-tests for loopback Utimens()
Browse files Browse the repository at this point in the history
Tests loopbackFileSystem.Utimens() and loopbackfile.Utimens()
at 1-second precision.

The exising TestUtimesNano() test only works on Linux
because it relies on syscall.UtimesNano(), which is not
available on Darwin. The new tests call the Utimens()
functions directly, bypassing FUSE, and work on all
platforms.

Because Darwin does not have syscall.UtimesNano(),
getting the Utimens() implementation right is hard.

The tests currently fail on Darwin, underlining the
need for them ( rfjakob/gocryptfs#229 ):

$ go test ./fuse/nodefs
[...]
--- FAIL: TestLoopbackFileUtimens (0.00s)
	files_test.go:51: mtime has changed: 1525378914 -> 1073
	files_test.go:70: atime has changed: 1525291058 -> 1073
[...]

$ go test ./fuse/pathfs
--- FAIL: TestLoopbackFileSystemUtimens (0.00s)
	loopback_test.go:55: mtime has changed: 1525378929 -> 1073
	loopback_test.go:74: atime has changed: 1525291058 -> 1073
[...]
  • Loading branch information
rfjakob committed May 3, 2018
1 parent 41df6ec commit f3b21f4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
32 changes: 32 additions & 0 deletions fuse/nodefs/files_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2016 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package nodefs

import (
"io/ioutil"
"os"
"testing"
"time"

"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/internal/testutil"
)

// Check that loopbackFile.Utimens() works as expected
func TestLoopbackFileUtimens(t *testing.T) {
f2, err := ioutil.TempFile("", "TestLoopbackFileUtimens")
if err != nil {
t.Fatal(err)
}
path := f2.Name()
defer os.Remove(path)
defer f2.Close()
f := NewLoopbackFile(f2)

utimensFn := func(atime *time.Time, mtime *time.Time) fuse.Status {
return f.Utimens(atime, mtime)
}
testutil.TestLoopbackUtimens(t, path, utimensFn)
}
35 changes: 35 additions & 0 deletions fuse/pathfs/loopback_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2016 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package pathfs

import (
"io/ioutil"
"os"
"path/filepath"
"syscall"
"testing"
"time"

"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/internal/testutil"
)

// Check that loopbackFileSystem.Utimens() works as expected
func TestLoopbackFileSystemUtimens(t *testing.T) {
fs := NewLoopbackFileSystem(os.TempDir())
f, err := ioutil.TempFile("", "TestLoopbackFileSystemUtimens")
if err != nil {
t.Fatal(err)
}
path := f.Name()
name := filepath.Base(path)
f.Close()
defer syscall.Unlink(path)

utimensFn := func(atime *time.Time, mtime *time.Time) fuse.Status {
return fs.Utimens(name, atime, mtime, nil)
}
testutil.TestLoopbackUtimens(t, path, utimensFn)
}

0 comments on commit f3b21f4

Please sign in to comment.