summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/matrix/matrix_test.go72
1 files changed, 25 insertions, 47 deletions
diff --git a/tests/matrix/matrix_test.go b/tests/matrix/matrix_test.go
index 1c94cb6..8aa5c9c 100644
--- a/tests/matrix/matrix_test.go
+++ b/tests/matrix/matrix_test.go
@@ -631,13 +631,27 @@ func TestLchown(t *testing.T) {
}
}
-// Set nanoseconds by path, normal file
-func TestUtimesNano(t *testing.T) {
- path := test_helpers.DefaultPlainDir + "/utimesnano"
- err := ioutil.WriteFile(path, []byte("foobar"), 0600)
+// Set nanoseconds by path, symlink
+func TestUtimesNanoSymlink(t *testing.T) {
+ path := test_helpers.DefaultPlainDir + "/utimesnano_symlink"
+ err := os.Symlink("/some/nonexisting/file", path)
if err != nil {
t.Fatal(err)
}
+ // syscall.UtimesNano does not provide a way to pass AT_SYMLINK_NOFOLLOW,
+ // so we call the external utility "touch", which does.
+ cmd := exec.Command("touch", "--no-dereference", path)
+ cmd.Stderr = os.Stderr
+ cmd.Stdout = os.Stdout
+ err = cmd.Run()
+ if err != nil {
+ t.Error(err)
+ }
+}
+
+// doTestUtimesNano verifies that setting nanosecond-precision times on "path"
+// works correctly. Pass "/proc/self/fd/N" to test a file descriptor.
+func doTestUtimesNano(t *testing.T, path string) {
ts := make([]syscall.Timespec, 2)
// atime
ts[0].Sec = 1
@@ -645,7 +659,7 @@ func TestUtimesNano(t *testing.T) {
// mtime
ts[1].Sec = 3
ts[1].Nsec = 4
- err = syscall.UtimesNano(path, ts)
+ err := syscall.UtimesNano(path, ts)
if err != nil {
t.Fatal(err)
}
@@ -666,22 +680,14 @@ func TestUtimesNano(t *testing.T) {
}
}
-// Set nanoseconds by path, symlink
-func TestUtimesNanoSymlink(t *testing.T) {
- path := test_helpers.DefaultPlainDir + "/utimesnano_symlink"
- err := os.Symlink("/some/nonexisting/file", path)
+// Set nanoseconds by path, normal file
+func TestUtimesNano(t *testing.T) {
+ path := test_helpers.DefaultPlainDir + "/utimesnano"
+ err := ioutil.WriteFile(path, []byte("foobar"), 0600)
if err != nil {
t.Fatal(err)
}
- // syscall.UtimesNano does not provide a way to pass AT_SYMLINK_NOFOLLOW,
- // so we call the external utility "touch", which does.
- cmd := exec.Command("touch", "--no-dereference", path)
- cmd.Stderr = os.Stderr
- cmd.Stdout = os.Stdout
- err = cmd.Run()
- if err != nil {
- t.Error(err)
- }
+ doTestUtimesNano(t, path)
}
// Set nanoseconds by fd
@@ -691,34 +697,6 @@ func TestUtimesNanoFd(t *testing.T) {
if err != nil {
t.Fatal(err)
}
-
- ts := make([]syscall.Timespec, 2)
- // atime
- ts[0].Sec = 5
- ts[0].Nsec = 6
- // mtime
- ts[1].Sec = 7
- ts[1].Nsec = 8
-
procPath := fmt.Sprintf("/proc/self/fd/%d", f.Fd())
- err = syscall.UtimesNano(procPath, ts)
- if err != nil {
- t.Fatalf("%s: %v", procPath, err)
- }
-
- var st syscall.Stat_t
- err = syscall.Stat(path, &st)
- if err != nil {
- t.Fatal(err)
- }
- if st.Atim != ts[0] {
- if st.Atim.Nsec == 0 {
- // TODO remove this once the pull request is merged
- t.Skip("Known limitation, https://github.com/hanwen/go-fuse/pull/131")
- }
- t.Errorf("Wrong atime: %v, want: %v", st.Atim, ts[0])
- }
- if st.Mtim != ts[1] {
- t.Errorf("Wrong mtime: %v, want: %v", st.Mtim, ts[1])
- }
+ doTestUtimesNano(t, procPath)
}