github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/pkg/system/stat_unix_test.go (about)

     1  // +build linux freebsd
     2  
     3  package system // import "github.com/demonoid81/moby/pkg/system"
     4  
     5  import (
     6  	"os"
     7  	"syscall"
     8  	"testing"
     9  
    10  	"gotest.tools/v3/assert"
    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  	assert.NilError(t, err)
    21  
    22  	s, err := fromStatT(stat)
    23  	assert.NilError(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  }