mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Recfactor: Use dockerCmd when possible in integration-cli tests
Part of #14603 integration-cli/docker_cli_links_test.go (coolljt0725) integration-cli/docker_cli_links_unix_test.go (coolljt0725) integration-cli/docker_cli_logs_test.go (coolljt0725) integration-cli/docker_cli_nat_test.go (coolljt0725) integration-cli/docker_cli_network_test.go (coolljt0725) integration-cli/docker_cli_stats_test.go (coolljt0725) integration-cli/docker_cli_tag_test.go (coolljt0725) integration-cli/docker_cli_top_test.go (coolljt0725) integration-cli/docker_cli_version_test.go (coolljt0725) integration-cli/docker_cli_wait_test.go (coolljt0725 Signed-off-by: Lei Jitang <leijitang@huawei.com>
This commit is contained in:
@@ -1,27 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestTopMultipleArgs(c *check.C) {
|
||||
runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "top")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
c.Fatalf("failed to start the container: %s, %v", out, err)
|
||||
}
|
||||
out, _ := dockerCmd(c, "run", "-i", "-d", "busybox", "top")
|
||||
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
||||
topCmd := exec.Command(dockerBinary, "top", cleanedContainerID, "-o", "pid")
|
||||
out, _, err = runCommandWithOutput(topCmd)
|
||||
if err != nil {
|
||||
c.Fatalf("failed to run top: %s, %v", out, err)
|
||||
}
|
||||
|
||||
out, _ = dockerCmd(c, "top", cleanedContainerID, "-o", "pid")
|
||||
if !strings.Contains(out, "PID") {
|
||||
c.Fatalf("did not see PID after top -o pid: %s", out)
|
||||
}
|
||||
@@ -29,30 +19,12 @@ func (s *DockerSuite) TestTopMultipleArgs(c *check.C) {
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestTopNonPrivileged(c *check.C) {
|
||||
runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "top")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
c.Fatalf("failed to start the container: %s, %v", out, err)
|
||||
}
|
||||
|
||||
out, _ := dockerCmd(c, "run", "-i", "-d", "busybox", "top")
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
||||
topCmd := exec.Command(dockerBinary, "top", cleanedContainerID)
|
||||
out1, _, err := runCommandWithOutput(topCmd)
|
||||
if err != nil {
|
||||
c.Fatalf("failed to run top: %s, %v", out1, err)
|
||||
}
|
||||
|
||||
topCmd = exec.Command(dockerBinary, "top", cleanedContainerID)
|
||||
out2, _, err := runCommandWithOutput(topCmd)
|
||||
if err != nil {
|
||||
c.Fatalf("failed to run top: %s, %v", out2, err)
|
||||
}
|
||||
|
||||
killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID)
|
||||
if out, _, err = runCommandWithOutput(killCmd); err != nil {
|
||||
c.Fatalf("failed to kill container: %s, %v", out, err)
|
||||
}
|
||||
out1, _ := dockerCmd(c, "top", cleanedContainerID)
|
||||
out2, _ := dockerCmd(c, "top", cleanedContainerID)
|
||||
out, _ = dockerCmd(c, "kill", cleanedContainerID)
|
||||
|
||||
if !strings.Contains(out1, "top") && !strings.Contains(out2, "top") {
|
||||
c.Fatal("top should've listed `top` in the process list, but failed twice")
|
||||
@@ -65,30 +37,12 @@ func (s *DockerSuite) TestTopNonPrivileged(c *check.C) {
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestTopPrivileged(c *check.C) {
|
||||
runCmd := exec.Command(dockerBinary, "run", "--privileged", "-i", "-d", "busybox", "top")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
c.Fatalf("failed to start the container: %s, %v", out, err)
|
||||
}
|
||||
|
||||
out, _ := dockerCmd(c, "run", "--privileged", "-i", "-d", "busybox", "top")
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
||||
topCmd := exec.Command(dockerBinary, "top", cleanedContainerID)
|
||||
out1, _, err := runCommandWithOutput(topCmd)
|
||||
if err != nil {
|
||||
c.Fatalf("failed to run top: %s, %v", out1, err)
|
||||
}
|
||||
|
||||
topCmd = exec.Command(dockerBinary, "top", cleanedContainerID)
|
||||
out2, _, err := runCommandWithOutput(topCmd)
|
||||
if err != nil {
|
||||
c.Fatalf("failed to run top: %s, %v", out2, err)
|
||||
}
|
||||
|
||||
killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID)
|
||||
if out, _, err = runCommandWithOutput(killCmd); err != nil {
|
||||
c.Fatalf("failed to kill container: %s, %v", out, err)
|
||||
}
|
||||
out1, _ := dockerCmd(c, "top", cleanedContainerID)
|
||||
out2, _ := dockerCmd(c, "top", cleanedContainerID)
|
||||
out, _ = dockerCmd(c, "kill", cleanedContainerID)
|
||||
|
||||
if !strings.Contains(out1, "top") && !strings.Contains(out2, "top") {
|
||||
c.Fatal("top should've listed `top` in the process list, but failed twice")
|
||||
|
||||
Reference in New Issue
Block a user