github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/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  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  // TestFromStatT tests fromStatT for a tempfile
    14  func TestFromStatT(t *testing.T) {
    15  	file, _, _, dir := prepareFiles(t)
    16  	defer os.RemoveAll(dir)
    17  
    18  	stat := &syscall.Stat_t{}
    19  	err := syscall.Lstat(file, stat)
    20  	require.NoError(t, err)
    21  
    22  	s, err := fromStatT(stat)
    23  	require.NoError(t, err)
    24  
    25  	if stat.Mode != s.Mode() {
    26  		t.Fatal("got invalid mode")
    27  	}
    28  	if stat.Uid != s.UID() {
    29  		t.Fatal("got invalid uid")
    30  	}
    31  	if stat.Gid != s.GID() {
    32  		t.Fatal("got invalid gid")
    33  	}
    34  	if stat.Rdev != s.Rdev() {
    35  		t.Fatal("got invalid rdev")
    36  	}
    37  	if stat.Mtim != s.Mtim() {
    38  		t.Fatal("got invalid mtim")
    39  	}
    40  }