github.com/jingleWang/moby@v1.13.1/pkg/system/stat_unix_test.go (about)

     1  // +build linux freebsd
     2  
     3  package system
     4  
     5  import (
     6  	"os"
     7  	"syscall"
     8  	"testing"
     9  )
    10  
    11  // TestFromStatT tests fromStatT for a tempfile
    12  func TestFromStatT(t *testing.T) {
    13  	file, _, _, dir := prepareFiles(t)
    14  	defer os.RemoveAll(dir)
    15  
    16  	stat := &syscall.Stat_t{}
    17  	err := syscall.Lstat(file, stat)
    18  
    19  	s, err := fromStatT(stat)
    20  	if err != nil {
    21  		t.Fatal(err)
    22  	}
    23  
    24  	if stat.Mode != s.Mode() {
    25  		t.Fatal("got invalid mode")
    26  	}
    27  	if stat.Uid != s.UID() {
    28  		t.Fatal("got invalid uid")
    29  	}
    30  	if stat.Gid != s.GID() {
    31  		t.Fatal("got invalid gid")
    32  	}
    33  	if stat.Rdev != s.Rdev() {
    34  		t.Fatal("got invalid rdev")
    35  	}
    36  	if stat.Mtim != s.Mtim() {
    37  		t.Fatal("got invalid mtim")
    38  	}
    39  }