From bb1b7fe501d333cab459445f9bffa0237febaa96 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 23 Oct 2017 14:01:38 +0200 Subject: [PATCH] unix: add test for UtimesNanoAt on Linux Add a test for UtimesNanoAt which makes sure the timestamp of a symlink is updated. Change-Id: I819e43db1d390fb37f011b34e58ff9d3d06595f1 Reviewed-on: https://go-review.googlesource.com/72377 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- unix/syscall_linux_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/unix/syscall_linux_test.go b/unix/syscall_linux_test.go index c0ab2db9..9c057eb1 100644 --- a/unix/syscall_linux_test.go +++ b/unix/syscall_linux_test.go @@ -184,6 +184,38 @@ func TestUtime(t *testing.T) { } } +func TestUtimesNanoAt(t *testing.T) { + defer chtmpdir(t)() + + symlink := "symlink1" + os.Remove(symlink) + err := os.Symlink("nonexisting", symlink) + if err != nil { + t.Fatal(err) + } + + ts := []unix.Timespec{ + {Sec: 1111, Nsec: 2222}, + {Sec: 3333, Nsec: 4444}, + } + err = unix.UtimesNanoAt(unix.AT_FDCWD, symlink, ts, unix.AT_SYMLINK_NOFOLLOW) + if err != nil { + t.Fatalf("UtimesNanoAt: %v", err) + } + + var st unix.Stat_t + err = unix.Lstat(symlink, &st) + if err != nil { + t.Fatalf("Lstat: %v", err) + } + if st.Atim != ts[0] { + t.Errorf("UtimesNanoAt: wrong atime: %v", st.Atim) + } + if st.Mtim != ts[1] { + t.Errorf("UtimesNanoAt: wrong mtime: %v", st.Mtim) + } +} + func TestGetrlimit(t *testing.T) { var rlim unix.Rlimit err := unix.Getrlimit(unix.RLIMIT_AS, &rlim)