github.com/hanwen/go-fuse@v1.0.0/fuse/pathfs/syscall_test.go (about)

     1  // Copyright 2016 the Go-FUSE 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  // +build linux
     6  
     7  package pathfs
     8  
     9  import (
    10  	"os"
    11  	"reflect"
    12  	"syscall"
    13  	"testing"
    14  )
    15  
    16  func TestSysUtimensat(t *testing.T) {
    17  	symlink := "/tmp/TestSysUtimensat"
    18  	os.Remove(symlink)
    19  	err := os.Symlink("/nonexisting/file", symlink)
    20  	if err != nil {
    21  		t.Fatal(err)
    22  	}
    23  
    24  	var ts [2]syscall.Timespec
    25  	// Atime
    26  	ts[0].Nsec = 1111
    27  	ts[0].Sec = 2222
    28  	// Mtime
    29  	ts[1].Nsec = 3333
    30  	ts[1].Sec = 4444
    31  
    32  	// Linux specific.
    33  	err = sysUtimensat(0, symlink, &ts, _AT_SYMLINK_NOFOLLOW)
    34  	if err != nil {
    35  		t.Fatal(err)
    36  	}
    37  
    38  	var st syscall.Stat_t
    39  	err = syscall.Lstat(symlink, &st)
    40  	if err != nil {
    41  		t.Fatal(err)
    42  	}
    43  	if !reflect.DeepEqual(st.Atim, ts[0]) {
    44  		t.Errorf("Wrong atime: %v", st.Atim)
    45  	}
    46  	if !reflect.DeepEqual(st.Mtim, ts[1]) {
    47  		t.Errorf("Wrong mtime: %v", st.Mtim)
    48  	}
    49  }