Docker-DCO-1.1-Signed-off-by: Jessica Frazelle <jess@docker.com> (github: jfrazelle)
| ... | ... |
@@ -1,7 +1,6 @@ |
| 1 | 1 |
package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "fmt" |
|
| 5 | 4 |
"os/exec" |
| 6 | 5 |
"strings" |
| 7 | 6 |
"testing" |
| ... | ... |
@@ -10,17 +9,21 @@ import ( |
| 10 | 10 |
func TestTopMultipleArgs(t *testing.T) {
|
| 11 | 11 |
runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "sleep", "20") |
| 12 | 12 |
out, _, err := runCommandWithOutput(runCmd) |
| 13 |
- errorOut(err, t, fmt.Sprintf("failed to start the container: %v", err))
|
|
| 13 |
+ if err != nil {
|
|
| 14 |
+ t.Fatalf("failed to start the container: %s, %v", out, err)
|
|
| 15 |
+ } |
|
| 14 | 16 |
|
| 15 | 17 |
cleanedContainerID := stripTrailingCharacters(out) |
| 16 | 18 |
defer deleteContainer(cleanedContainerID) |
| 17 | 19 |
|
| 18 | 20 |
topCmd := exec.Command(dockerBinary, "top", cleanedContainerID, "-o", "pid") |
| 19 | 21 |
out, _, err = runCommandWithOutput(topCmd) |
| 20 |
- errorOut(err, t, fmt.Sprintf("failed to run top: %v %v", out, err))
|
|
| 22 |
+ if err != nil {
|
|
| 23 |
+ t.Fatalf("failed to run top: %s, %v", out, err)
|
|
| 24 |
+ } |
|
| 21 | 25 |
|
| 22 | 26 |
if !strings.Contains(out, "PID") {
|
| 23 |
- errorOut(nil, t, fmt.Sprintf("did not see PID after top -o pid"))
|
|
| 27 |
+ t.Fatalf("did not see PID after top -o pid: %s", out)
|
|
| 24 | 28 |
} |
| 25 | 29 |
|
| 26 | 30 |
logDone("top - multiple arguments")
|
| ... | ... |
@@ -29,27 +32,34 @@ func TestTopMultipleArgs(t *testing.T) {
|
| 29 | 29 |
func TestTopNonPrivileged(t *testing.T) {
|
| 30 | 30 |
runCmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox", "sleep", "20") |
| 31 | 31 |
out, _, err := runCommandWithOutput(runCmd) |
| 32 |
- errorOut(err, t, fmt.Sprintf("failed to start the container: %v", err))
|
|
| 32 |
+ if err != nil {
|
|
| 33 |
+ t.Fatalf("failed to start the container: %s, %v", out, err)
|
|
| 34 |
+ } |
|
| 33 | 35 |
|
| 34 | 36 |
cleanedContainerID := stripTrailingCharacters(out) |
| 35 | 37 |
|
| 36 | 38 |
topCmd := exec.Command(dockerBinary, "top", cleanedContainerID) |
| 37 |
- out, _, err = runCommandWithOutput(topCmd) |
|
| 38 |
- errorOut(err, t, fmt.Sprintf("failed to run top: %v %v", out, err))
|
|
| 39 |
+ out1, _, err := runCommandWithOutput(topCmd) |
|
| 40 |
+ if err != nil {
|
|
| 41 |
+ t.Fatalf("failed to run top: %s, %v", out1, err)
|
|
| 42 |
+ } |
|
| 39 | 43 |
|
| 40 | 44 |
topCmd = exec.Command(dockerBinary, "top", cleanedContainerID) |
| 41 |
- out2, _, err2 := runCommandWithOutput(topCmd) |
|
| 42 |
- errorOut(err2, t, fmt.Sprintf("failed to run top: %v %v", out2, err2))
|
|
| 45 |
+ out2, _, err := runCommandWithOutput(topCmd) |
|
| 46 |
+ if err != nil {
|
|
| 47 |
+ t.Fatalf("failed to run top: %s, %v", out2, err)
|
|
| 48 |
+ } |
|
| 43 | 49 |
|
| 44 | 50 |
killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID) |
| 45 |
- _, err = runCommand(killCmd) |
|
| 46 |
- errorOut(err, t, fmt.Sprintf("failed to kill container: %v", err))
|
|
| 51 |
+ if out, _, err = runCommandWithOutput(killCmd); err != nil {
|
|
| 52 |
+ t.Fatalf("failed to kill container: %s, %v", out, err)
|
|
| 53 |
+ } |
|
| 47 | 54 |
|
| 48 | 55 |
deleteContainer(cleanedContainerID) |
| 49 | 56 |
|
| 50 |
- if !strings.Contains(out, "sleep 20") && !strings.Contains(out2, "sleep 20") {
|
|
| 57 |
+ if !strings.Contains(out1, "sleep 20") && !strings.Contains(out2, "sleep 20") {
|
|
| 51 | 58 |
t.Fatal("top should've listed `sleep 20` in the process list, but failed twice")
|
| 52 |
- } else if !strings.Contains(out, "sleep 20") {
|
|
| 59 |
+ } else if !strings.Contains(out1, "sleep 20") {
|
|
| 53 | 60 |
t.Fatal("top should've listed `sleep 20` in the process list, but failed the first time")
|
| 54 | 61 |
} else if !strings.Contains(out2, "sleep 20") {
|
| 55 | 62 |
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) {
|
| 61 | 61 |
func TestTopPrivileged(t *testing.T) {
|
| 62 | 62 |
runCmd := exec.Command(dockerBinary, "run", "--privileged", "-i", "-d", "busybox", "sleep", "20") |
| 63 | 63 |
out, _, err := runCommandWithOutput(runCmd) |
| 64 |
- errorOut(err, t, fmt.Sprintf("failed to start the container: %v", err))
|
|
| 64 |
+ if err != nil {
|
|
| 65 |
+ t.Fatalf("failed to start the container: %s, %v", out, err)
|
|
| 66 |
+ } |
|
| 65 | 67 |
|
| 66 | 68 |
cleanedContainerID := stripTrailingCharacters(out) |
| 67 | 69 |
|
| 68 | 70 |
topCmd := exec.Command(dockerBinary, "top", cleanedContainerID) |
| 69 |
- out, _, err = runCommandWithOutput(topCmd) |
|
| 70 |
- errorOut(err, t, fmt.Sprintf("failed to run top: %v %v", out, err))
|
|
| 71 |
+ out1, _, err := runCommandWithOutput(topCmd) |
|
| 72 |
+ if err != nil {
|
|
| 73 |
+ t.Fatalf("failed to run top: %s, %v", out1, err)
|
|
| 74 |
+ } |
|
| 71 | 75 |
|
| 72 | 76 |
topCmd = exec.Command(dockerBinary, "top", cleanedContainerID) |
| 73 |
- out2, _, err2 := runCommandWithOutput(topCmd) |
|
| 74 |
- errorOut(err2, t, fmt.Sprintf("failed to run top: %v %v", out2, err2))
|
|
| 77 |
+ out2, _, err := runCommandWithOutput(topCmd) |
|
| 78 |
+ if err != nil {
|
|
| 79 |
+ t.Fatalf("failed to run top: %s, %v", out2, err)
|
|
| 80 |
+ } |
|
| 75 | 81 |
|
| 76 | 82 |
killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID) |
| 77 |
- _, err = runCommand(killCmd) |
|
| 78 |
- errorOut(err, t, fmt.Sprintf("failed to kill container: %v", err))
|
|
| 83 |
+ if out, _, err = runCommandWithOutput(killCmd); err != nil {
|
|
| 84 |
+ t.Fatalf("failed to kill container: %s, %v", out, err)
|
|
| 85 |
+ } |
|
| 79 | 86 |
|
| 80 | 87 |
deleteContainer(cleanedContainerID) |
| 81 | 88 |
|
| 82 |
- if !strings.Contains(out, "sleep 20") && !strings.Contains(out2, "sleep 20") {
|
|
| 89 |
+ if !strings.Contains(out1, "sleep 20") && !strings.Contains(out2, "sleep 20") {
|
|
| 83 | 90 |
t.Fatal("top should've listed `sleep 20` in the process list, but failed twice")
|
| 84 |
- } else if !strings.Contains(out, "sleep 20") {
|
|
| 91 |
+ } else if !strings.Contains(out1, "sleep 20") {
|
|
| 85 | 92 |
t.Fatal("top should've listed `sleep 20` in the process list, but failed the first time")
|
| 86 | 93 |
} else if !strings.Contains(out2, "sleep 20") {
|
| 87 | 94 |
t.Fatal("top should've listed `sleep 20` in the process list, but failed the second itime")
|