integration-cli: remove uses of pkg/system.Stat()

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-10-09 17:55:13 +02:00
parent 9582dd10e1
commit 0242fef89c
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 14 additions and 11 deletions

View file

@ -10,9 +10,9 @@ import (
"path/filepath"
"strconv"
"strings"
"syscall"
"testing"
"github.com/docker/docker/pkg/system"
"gotest.tools/v3/assert"
)
@ -59,12 +59,13 @@ func (s *DockerCLICpSuite) TestCpCheckDestOwnership(c *testing.T) {
assert.NilError(c, runDockerCp(c, srcPath, dstPath))
stat, err := system.Stat(filepath.Join(tmpVolDir, "file1"))
stat, err := os.Stat(filepath.Join(tmpVolDir, "file1"))
assert.NilError(c, err)
uid, gid, err := getRootUIDGID()
assert.NilError(c, err)
assert.Equal(c, stat.UID(), uint32(uid), "Copied file not owned by container root UID")
assert.Equal(c, stat.GID(), uint32(gid), "Copied file not owned by container root GID")
fi := stat.Sys().(*syscall.Stat_t)
assert.Equal(c, fi.Uid, uint32(uid), "Copied file not owned by container root UID")
assert.Equal(c, fi.Gid, uint32(gid), "Copied file not owned by container root GID")
}
func getRootUIDGID() (int, int, error) {

View file

@ -11,10 +11,10 @@ import (
"path/filepath"
"strconv"
"strings"
"syscall"
"testing"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/pkg/system"
"gotest.tools/v3/assert"
)
@ -53,10 +53,11 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *testing.T) {
assert.Equal(c, uidgid[0], user)
// check that the created directory is owned by remapped uid:gid
statNotExists, err := system.Stat(tmpDirNotExists)
statNotExists, err := os.Stat(tmpDirNotExists)
assert.NilError(c, err)
assert.Equal(c, statNotExists.UID(), uint32(uid), "Created directory not owned by remapped root UID")
assert.Equal(c, statNotExists.GID(), uint32(gid), "Created directory not owned by remapped root GID")
fi := statNotExists.Sys().(*syscall.Stat_t)
assert.Equal(c, fi.Uid, uint32(uid), "Created directory not owned by remapped root UID")
assert.Equal(c, fi.Gid, uint32(gid), "Created directory not owned by remapped root GID")
pid, err := s.d.Cmd("inspect", "--format={{.State.Pid}}", "userns")
assert.Assert(c, err == nil, "Could not inspect running container: out: %q", pid)
@ -73,10 +74,11 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *testing.T) {
assert.NilError(c, err)
// check that the touched file is owned by remapped uid:gid
stat, err := system.Stat(filepath.Join(tmpDir, "testfile"))
stat, err := os.Stat(filepath.Join(tmpDir, "testfile"))
assert.NilError(c, err)
assert.Equal(c, stat.UID(), uint32(uid), "Touched file not owned by remapped root UID")
assert.Equal(c, stat.GID(), uint32(gid), "Touched file not owned by remapped root GID")
fi = stat.Sys().(*syscall.Stat_t)
assert.Equal(c, fi.Uid, uint32(uid), "Touched file not owned by remapped root UID")
assert.Equal(c, fi.Gid, uint32(gid), "Touched file not owned by remapped root GID")
// use host usernamespace
out, err = s.d.Cmd("run", "-d", "--name", "userns_skip", "--userns", "host", "busybox", "sh", "-c", "touch /goofy/testfile; exec top")