2014-02-25 18:17:48 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTop(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))
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID)
|
|
|
|
_, err = runCommand(killCmd)
|
|
|
|
errorOut(err, t, fmt.Sprintf("failed to kill container: %v", err))
|
|
|
|
|
2014-04-04 03:22:32 +03:00
|
|
|
deleteContainer(cleanedContainerID)
|
2014-02-25 18:17:48 +02:00
|
|
|
|
|
|
|
if !strings.Contains(out, "sleep 20") {
|
|
|
|
t.Fatal("top should've listed sleep 20 in the process list")
|
|
|
|
}
|
|
|
|
|
|
|
|
logDone("top - sleep process should be listed")
|
|
|
|
}
|