mirror of
https://github.com/golang/sys.git
synced 2026-02-09 04:06:04 +03:00
unix: test UtimesNanoAt on darwin
Change-Id: I18354d29db909227ae75df1c8b1ab7888375f8db Reviewed-on: https://go-review.googlesource.com/c/147740 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
committed by
Tobias Klauser
parent
3a27cdcbcf
commit
3a76605856
@@ -4,6 +4,13 @@
|
||||
|
||||
package unix_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// stringsFromByteSlice converts a sequence of attributes to a []string.
|
||||
// On Darwin, each entry is a NULL-terminated string.
|
||||
func stringsFromByteSlice(buf []byte) []string {
|
||||
@@ -17,3 +24,40 @@ func stringsFromByteSlice(buf []byte) []string {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
// Only check Mtimespec, Atimespec might not be supported by the underlying filesystem
|
||||
expected := ts[1]
|
||||
if st.Mtimespec.Nsec == 0 {
|
||||
// Some filesystems only support 1-second time stamp resolution
|
||||
// and will always set Nsec to 0.
|
||||
expected.Nsec = 0
|
||||
}
|
||||
if st.Mtimespec != expected {
|
||||
t.Errorf("UtimesNanoAt: wrong mtime: got %v, expected %v", st.Mtimespec, expected)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user