mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Cleanup errorOut resp in top tests
Docker-DCO-1.1-Signed-off-by: Jessica Frazelle <jess@docker.com> (github: jfrazelle)
This commit is contained in:
parent
b1e3c9e9cd
commit
764030ec92
1 changed files with 39 additions and 22 deletions
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
|
@ -10,17 +9,21 @@ import (
|
|||
func TestTopMultipleArgs(t *testing.T) {
|
||||
runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "sleep", "20")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
errorOut(err, t, fmt.Sprintf("failed to start the container: %v", err))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to start the container: %s, %v", out, err)
|
||||
}
|
||||
|
||||
cleanedContainerID := stripTrailingCharacters(out)
|
||||
defer deleteContainer(cleanedContainerID)
|
||||
|
||||
topCmd := exec.Command(dockerBinary, "top", cleanedContainerID, "-o", "pid")
|
||||
out, _, err = runCommandWithOutput(topCmd)
|
||||
errorOut(err, t, fmt.Sprintf("failed to run top: %v %v", out, err))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to run top: %s, %v", out, err)
|
||||
}
|
||||
|
||||
if !strings.Contains(out, "PID") {
|
||||
errorOut(nil, t, fmt.Sprintf("did not see PID after top -o pid"))
|
||||
t.Fatalf("did not see PID after top -o pid: %s", out)
|
||||
}
|
||||
|
||||
logDone("top - multiple arguments")
|
||||
|
@ -29,27 +32,34 @@ func TestTopMultipleArgs(t *testing.T) {
|
|||
func TestTopNonPrivileged(t *testing.T) {
|
||||
runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "sleep", "20")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
errorOut(err, t, fmt.Sprintf("failed to start the container: %v", err))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to start the container: %s, %v", out, err)
|
||||
}
|
||||
|
||||
cleanedContainerID := stripTrailingCharacters(out)
|
||||
|
||||
topCmd := exec.Command(dockerBinary, "top", cleanedContainerID)
|
||||
out, _, err = runCommandWithOutput(topCmd)
|
||||
errorOut(err, t, fmt.Sprintf("failed to run top: %v %v", out, err))
|
||||
out1, _, err := runCommandWithOutput(topCmd)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to run top: %s, %v", out1, err)
|
||||
}
|
||||
|
||||
topCmd = exec.Command(dockerBinary, "top", cleanedContainerID)
|
||||
out2, _, err2 := runCommandWithOutput(topCmd)
|
||||
errorOut(err2, t, fmt.Sprintf("failed to run top: %v %v", out2, err2))
|
||||
out2, _, err := runCommandWithOutput(topCmd)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to run top: %s, %v", out2, err)
|
||||
}
|
||||
|
||||
killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID)
|
||||
_, err = runCommand(killCmd)
|
||||
errorOut(err, t, fmt.Sprintf("failed to kill container: %v", err))
|
||||
if out, _, err = runCommandWithOutput(killCmd); err != nil {
|
||||
t.Fatalf("failed to kill container: %s, %v", out, err)
|
||||
}
|
||||
|
||||
deleteContainer(cleanedContainerID)
|
||||
|
||||
if !strings.Contains(out, "sleep 20") && !strings.Contains(out2, "sleep 20") {
|
||||
if !strings.Contains(out1, "sleep 20") && !strings.Contains(out2, "sleep 20") {
|
||||
t.Fatal("top should've listed `sleep 20` in the process list, but failed twice")
|
||||
} else if !strings.Contains(out, "sleep 20") {
|
||||
} else if !strings.Contains(out1, "sleep 20") {
|
||||
t.Fatal("top should've listed `sleep 20` in the process list, but failed the first time")
|
||||
} else if !strings.Contains(out2, "sleep 20") {
|
||||
t.Fatal("top should've listed `sleep 20` in the process list, but failed the second itime")
|
||||
|
@ -61,27 +71,34 @@ func TestTopNonPrivileged(t *testing.T) {
|
|||
func TestTopPrivileged(t *testing.T) {
|
||||
runCmd := exec.Command(dockerBinary, "run", "--privileged", "-i", "-d", "busybox", "sleep", "20")
|
||||
out, _, err := runCommandWithOutput(runCmd)
|
||||
errorOut(err, t, fmt.Sprintf("failed to start the container: %v", err))
|
||||
if err != nil {
|
||||
t.Fatalf("failed to start the container: %s, %v", out, err)
|
||||
}
|
||||
|
||||
cleanedContainerID := stripTrailingCharacters(out)
|
||||
|
||||
topCmd := exec.Command(dockerBinary, "top", cleanedContainerID)
|
||||
out, _, err = runCommandWithOutput(topCmd)
|
||||
errorOut(err, t, fmt.Sprintf("failed to run top: %v %v", out, err))
|
||||
out1, _, err := runCommandWithOutput(topCmd)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to run top: %s, %v", out1, err)
|
||||
}
|
||||
|
||||
topCmd = exec.Command(dockerBinary, "top", cleanedContainerID)
|
||||
out2, _, err2 := runCommandWithOutput(topCmd)
|
||||
errorOut(err2, t, fmt.Sprintf("failed to run top: %v %v", out2, err2))
|
||||
out2, _, err := runCommandWithOutput(topCmd)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to run top: %s, %v", out2, err)
|
||||
}
|
||||
|
||||
killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID)
|
||||
_, err = runCommand(killCmd)
|
||||
errorOut(err, t, fmt.Sprintf("failed to kill container: %v", err))
|
||||
if out, _, err = runCommandWithOutput(killCmd); err != nil {
|
||||
t.Fatalf("failed to kill container: %s, %v", out, err)
|
||||
}
|
||||
|
||||
deleteContainer(cleanedContainerID)
|
||||
|
||||
if !strings.Contains(out, "sleep 20") && !strings.Contains(out2, "sleep 20") {
|
||||
if !strings.Contains(out1, "sleep 20") && !strings.Contains(out2, "sleep 20") {
|
||||
t.Fatal("top should've listed `sleep 20` in the process list, but failed twice")
|
||||
} else if !strings.Contains(out, "sleep 20") {
|
||||
} else if !strings.Contains(out1, "sleep 20") {
|
||||
t.Fatal("top should've listed `sleep 20` in the process list, but failed the first time")
|
||||
} else if !strings.Contains(out2, "sleep 20") {
|
||||
t.Fatal("top should've listed `sleep 20` in the process list, but failed the second itime")
|
||||
|
|
Loading…
Reference in a new issue