2021-08-23 13:14:53 +00:00
|
|
|
//go:build linux || freebsd
|
2015-10-01 17:45:32 +00:00
|
|
|
|
2018-02-05 21:05:59 +00:00
|
|
|
package system // import "github.com/docker/docker/pkg/system"
|
2014-11-13 20:36:05 +00:00
|
|
|
|
|
|
|
import (
|
2014-11-20 17:33:15 +00:00
|
|
|
"os"
|
2022-10-07 13:44:50 +00:00
|
|
|
"path/filepath"
|
2014-11-13 20:36:05 +00:00
|
|
|
"syscall"
|
|
|
|
"testing"
|
2017-09-08 22:00:14 +00:00
|
|
|
|
2020-02-07 13:39:24 +00:00
|
|
|
"gotest.tools/v3/assert"
|
2014-11-13 20:36:05 +00:00
|
|
|
)
|
|
|
|
|
2015-03-31 08:03:31 +00:00
|
|
|
// TestFromStatT tests fromStatT for a tempfile
|
2014-11-13 20:36:05 +00:00
|
|
|
func TestFromStatT(t *testing.T) {
|
2022-10-07 13:44:50 +00:00
|
|
|
file := filepath.Join(t.TempDir(), "exist")
|
|
|
|
if err := os.WriteFile(file, []byte("hello"), 0o644); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2014-11-13 20:36:05 +00:00
|
|
|
|
|
|
|
stat := &syscall.Stat_t{}
|
|
|
|
err := syscall.Lstat(file, stat)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2014-11-13 20:36:05 +00:00
|
|
|
|
|
|
|
s, err := fromStatT(stat)
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
2014-11-13 20:36:05 +00:00
|
|
|
|
|
|
|
if stat.Mode != s.Mode() {
|
|
|
|
t.Fatal("got invalid mode")
|
|
|
|
}
|
2015-07-28 16:13:12 +00:00
|
|
|
if stat.Uid != s.UID() {
|
2014-11-13 20:36:05 +00:00
|
|
|
t.Fatal("got invalid uid")
|
|
|
|
}
|
2015-10-12 14:58:33 +00:00
|
|
|
if stat.Gid != s.GID() {
|
2014-11-13 20:36:05 +00:00
|
|
|
t.Fatal("got invalid gid")
|
|
|
|
}
|
2020-05-26 06:50:06 +00:00
|
|
|
//nolint:unconvert // conversion needed to fix mismatch types on mips64el
|
|
|
|
if uint64(stat.Rdev) != s.Rdev() {
|
2014-11-13 20:36:05 +00:00
|
|
|
t.Fatal("got invalid rdev")
|
|
|
|
}
|
|
|
|
if stat.Mtim != s.Mtim() {
|
|
|
|
t.Fatal("got invalid mtim")
|
|
|
|
}
|
|
|
|
}
|