mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
Use suite for integration-cli
It prints test name and duration for each test. Also performs deleteAllContainers after each test. Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
@@ -3,14 +3,15 @@ package main
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
func TestTopMultipleArgs(t *testing.T) {
|
||||
func (s *DockerSuite) TestTopMultipleArgs(c *check.C) {
|
||||
runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "top")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to start the container: %s, %v", out, err)
|
||||
c.Fatalf("failed to start the container: %s, %v", out, err)
|
||||
}
|
||||
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
@@ -19,21 +20,20 @@ func TestTopMultipleArgs(t *testing.T) {
|
||||
topCmd := exec.Command(dockerBinary, "top", cleanedContainerID, "-o", "pid")
|
||||
out, _, err = runCommandWithOutput(topCmd)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to run top: %s, %v", out, err)
|
||||
c.Fatalf("failed to run top: %s, %v", out, err)
|
||||
}
|
||||
|
||||
if !strings.Contains(out, "PID") {
|
||||
t.Fatalf("did not see PID after top -o pid: %s", out)
|
||||
c.Fatalf("did not see PID after top -o pid: %s", out)
|
||||
}
|
||||
|
||||
logDone("top - multiple arguments")
|
||||
}
|
||||
|
||||
func TestTopNonPrivileged(t *testing.T) {
|
||||
func (s *DockerSuite) TestTopNonPrivileged(c *check.C) {
|
||||
runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "top")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to start the container: %s, %v", out, err)
|
||||
c.Fatalf("failed to start the container: %s, %v", out, err)
|
||||
}
|
||||
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
@@ -41,38 +41,37 @@ func TestTopNonPrivileged(t *testing.T) {
|
||||
topCmd := exec.Command(dockerBinary, "top", cleanedContainerID)
|
||||
out1, _, err := runCommandWithOutput(topCmd)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to run top: %s, %v", out1, err)
|
||||
c.Fatalf("failed to run top: %s, %v", out1, err)
|
||||
}
|
||||
|
||||
topCmd = exec.Command(dockerBinary, "top", cleanedContainerID)
|
||||
out2, _, err := runCommandWithOutput(topCmd)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to run top: %s, %v", out2, err)
|
||||
c.Fatalf("failed to run top: %s, %v", out2, err)
|
||||
}
|
||||
|
||||
killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID)
|
||||
if out, _, err = runCommandWithOutput(killCmd); err != nil {
|
||||
t.Fatalf("failed to kill container: %s, %v", out, err)
|
||||
c.Fatalf("failed to kill container: %s, %v", out, err)
|
||||
}
|
||||
|
||||
deleteContainer(cleanedContainerID)
|
||||
|
||||
if !strings.Contains(out1, "top") && !strings.Contains(out2, "top") {
|
||||
t.Fatal("top should've listed `top` in the process list, but failed twice")
|
||||
c.Fatal("top should've listed `top` in the process list, but failed twice")
|
||||
} else if !strings.Contains(out1, "top") {
|
||||
t.Fatal("top should've listed `top` in the process list, but failed the first time")
|
||||
c.Fatal("top should've listed `top` in the process list, but failed the first time")
|
||||
} else if !strings.Contains(out2, "top") {
|
||||
t.Fatal("top should've listed `top` in the process list, but failed the second itime")
|
||||
c.Fatal("top should've listed `top` in the process list, but failed the second itime")
|
||||
}
|
||||
|
||||
logDone("top - top process should be listed in non privileged mode")
|
||||
}
|
||||
|
||||
func TestTopPrivileged(t *testing.T) {
|
||||
func (s *DockerSuite) TestTopPrivileged(c *check.C) {
|
||||
runCmd := exec.Command(dockerBinary, "run", "--privileged", "-i", "-d", "busybox", "top")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to start the container: %s, %v", out, err)
|
||||
c.Fatalf("failed to start the container: %s, %v", out, err)
|
||||
}
|
||||
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
@@ -80,29 +79,28 @@ func TestTopPrivileged(t *testing.T) {
|
||||
topCmd := exec.Command(dockerBinary, "top", cleanedContainerID)
|
||||
out1, _, err := runCommandWithOutput(topCmd)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to run top: %s, %v", out1, err)
|
||||
c.Fatalf("failed to run top: %s, %v", out1, err)
|
||||
}
|
||||
|
||||
topCmd = exec.Command(dockerBinary, "top", cleanedContainerID)
|
||||
out2, _, err := runCommandWithOutput(topCmd)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to run top: %s, %v", out2, err)
|
||||
c.Fatalf("failed to run top: %s, %v", out2, err)
|
||||
}
|
||||
|
||||
killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID)
|
||||
if out, _, err = runCommandWithOutput(killCmd); err != nil {
|
||||
t.Fatalf("failed to kill container: %s, %v", out, err)
|
||||
c.Fatalf("failed to kill container: %s, %v", out, err)
|
||||
}
|
||||
|
||||
deleteContainer(cleanedContainerID)
|
||||
|
||||
if !strings.Contains(out1, "top") && !strings.Contains(out2, "top") {
|
||||
t.Fatal("top should've listed `top` in the process list, but failed twice")
|
||||
c.Fatal("top should've listed `top` in the process list, but failed twice")
|
||||
} else if !strings.Contains(out1, "top") {
|
||||
t.Fatal("top should've listed `top` in the process list, but failed the first time")
|
||||
c.Fatal("top should've listed `top` in the process list, but failed the first time")
|
||||
} else if !strings.Contains(out2, "top") {
|
||||
t.Fatal("top should've listed `top` in the process list, but failed the second itime")
|
||||
c.Fatal("top should've listed `top` in the process list, but failed the second itime")
|
||||
}
|
||||
|
||||
logDone("top - top process should be listed in privileged mode")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user