github.com/go-xe2/third@v1.0.3/golang.org/x/sys/unix/syscall_darwin_test.go (about) 1 // Copyright 2018 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package unix_test 6 7 import ( 8 "os" 9 "testing" 10 11 "github.com/go-xe2/third/golang.org/x/sys/unix" 12 ) 13 14 // stringsFromByteSlice converts a sequence of attributes to a []string. 15 // On Darwin, each entry is a NULL-terminated string. 16 func stringsFromByteSlice(buf []byte) []string { 17 var result []string 18 off := 0 19 for i, b := range buf { 20 if b == 0 { 21 result = append(result, string(buf[off:i])) 22 off = i + 1 23 } 24 } 25 return result 26 } 27 28 func TestUtimesNanoAt(t *testing.T) { 29 defer chtmpdir(t)() 30 31 symlink := "symlink1" 32 os.Remove(symlink) 33 err := os.Symlink("nonexisting", symlink) 34 if err != nil { 35 t.Fatal(err) 36 } 37 38 ts := []unix.Timespec{ 39 {Sec: 1111, Nsec: 2222}, 40 {Sec: 3333, Nsec: 4444}, 41 } 42 err = unix.UtimesNanoAt(unix.AT_FDCWD, symlink, ts, unix.AT_SYMLINK_NOFOLLOW) 43 if err != nil { 44 t.Fatalf("UtimesNanoAt: %v", err) 45 } 46 47 var st unix.Stat_t 48 err = unix.Lstat(symlink, &st) 49 if err != nil { 50 t.Fatalf("Lstat: %v", err) 51 } 52 53 // Only check Mtimespec, Atimespec might not be supported by the underlying filesystem 54 expected := ts[1] 55 if st.Mtimespec.Nsec == 0 { 56 // Some filesystems only support 1-second time stamp resolution 57 // and will always set Nsec to 0. 58 expected.Nsec = 0 59 } 60 if st.Mtimespec != expected { 61 t.Errorf("UtimesNanoAt: wrong mtime: got %v, expected %v", st.Mtimespec, expected) 62 } 63 }