integration-cli: DockerCLITopSuite: replace dockerCmd

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-07-28 10:30:17 +02:00
parent 6ce6b63482
commit 885eceba1d
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -5,6 +5,7 @@ import (
"strings"
"testing"
"github.com/docker/docker/integration-cli/cli"
"gotest.tools/v3/assert"
"gotest.tools/v3/icmd"
)
@ -32,7 +33,7 @@ func (s *DockerCLITopSuite) TestTopMultipleArgs(c *testing.T) {
default:
expected = icmd.Expected{Out: "PID"}
}
result := dockerCmdWithResult("top", cleanedContainerID, "-o", "pid")
result := cli.Docker(cli.Args("top", cleanedContainerID, "-o", "pid"))
result.Assert(c, expected)
}
@ -40,9 +41,9 @@ func (s *DockerCLITopSuite) TestTopNonPrivileged(c *testing.T) {
out := runSleepingContainer(c, "-d")
cleanedContainerID := strings.TrimSpace(out)
out1, _ := dockerCmd(c, "top", cleanedContainerID)
out2, _ := dockerCmd(c, "top", cleanedContainerID)
dockerCmd(c, "kill", cleanedContainerID)
out1 := cli.DockerCmd(c, "top", cleanedContainerID).Combined()
out2 := cli.DockerCmd(c, "top", cleanedContainerID).Combined()
cli.DockerCmd(c, "kill", cleanedContainerID)
// Windows will list the name of the launched executable which in this case is busybox.exe, without the parameters.
// Linux will display the command executed in the container
@ -62,9 +63,8 @@ func (s *DockerCLITopSuite) TestTopNonPrivileged(c *testing.T) {
// very different to Linux in this regard.
func (s *DockerCLITopSuite) TestTopWindowsCoreProcesses(c *testing.T) {
testRequires(c, DaemonIsWindows)
out := runSleepingContainer(c, "-d")
cleanedContainerID := strings.TrimSpace(out)
out1, _ := dockerCmd(c, "top", cleanedContainerID)
cID := runSleepingContainer(c, "-d")
out1 := cli.DockerCmd(c, "top", cID).Combined()
lookingFor := []string{"smss.exe", "csrss.exe", "wininit.exe", "services.exe", "lsass.exe", "CExecSvc.exe"}
for i, s := range lookingFor {
assert.Assert(c, strings.Contains(out1, s), "top should've listed `%s` in the process list, but failed. Test case %d", s, i)
@ -74,12 +74,12 @@ func (s *DockerCLITopSuite) TestTopWindowsCoreProcesses(c *testing.T) {
func (s *DockerCLITopSuite) TestTopPrivileged(c *testing.T) {
// Windows does not support --privileged
testRequires(c, DaemonIsLinux, NotUserNamespace)
out, _ := dockerCmd(c, "run", "--privileged", "-i", "-d", "busybox", "top")
cleanedContainerID := strings.TrimSpace(out)
cID := cli.DockerCmd(c, "run", "--privileged", "-i", "-d", "busybox", "top").Stdout()
cID = strings.TrimSpace(cID)
out1, _ := dockerCmd(c, "top", cleanedContainerID)
out2, _ := dockerCmd(c, "top", cleanedContainerID)
dockerCmd(c, "kill", cleanedContainerID)
out1 := cli.DockerCmd(c, "top", cID).Combined()
out2 := cli.DockerCmd(c, "top", cID).Combined()
cli.DockerCmd(c, "kill", cID)
assert.Assert(c, strings.Contains(out1, "top"), "top should've listed `top` in the process list, but failed the first time")
assert.Assert(c, strings.Contains(out2, "top"), "top should've listed `top` in the process list, but failed the second time")