move TestKillDifferentUser

Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
Victor Vieux 2014-08-27 23:34:37 +00:00
parent 7c27c7a096
commit eb9379c5d0
2 changed files with 28 additions and 58 deletions

View file

@ -34,3 +34,31 @@ func TestKillContainer(t *testing.T) {
logDone("kill - kill container running sleep 10")
}
func TestKillDifferentUserContainer(t *testing.T) {
runCmd := exec.Command(dockerBinary, "run", "-u", "daemon", "-d", "busybox", "sh", "-c", "sleep 10")
out, _, err := runCommandWithOutput(runCmd)
errorOut(err, t, fmt.Sprintf("run failed with errors: %v", err))
cleanedContainerID := stripTrailingCharacters(out)
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID)
inspectOut, _, err := runCommandWithOutput(inspectCmd)
errorOut(err, t, fmt.Sprintf("out should've been a container id: %v %v", inspectOut, err))
killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID)
out, _, err = runCommandWithOutput(killCmd)
errorOut(err, t, fmt.Sprintf("failed to kill container: %v %v", out, err))
listRunningContainersCmd := exec.Command(dockerBinary, "ps", "-q")
out, _, err = runCommandWithOutput(listRunningContainersCmd)
errorOut(err, t, fmt.Sprintf("failed to list running containers: %v", err))
if strings.Contains(out, cleanedContainerID) {
t.Fatal("killed container is still running")
}
deleteContainer(cleanedContainerID)
logDone("kill - kill container running sleep 10 from a different user")
}

View file

@ -13,64 +13,6 @@ import (
"github.com/docker/docker/runconfig"
)
func TestKillDifferentUser(t *testing.T) {
daemon := mkDaemon(t)
defer nuke(daemon)
container, _, err := daemon.Create(&runconfig.Config{
Image: GetTestImage(daemon).ID,
Cmd: []string{"cat"},
OpenStdin: true,
User: "daemon",
},
"",
)
if err != nil {
t.Fatal(err)
}
defer daemon.Destroy(container)
// FIXME @shykes: this seems redundant, but is very old, I'm leaving it in case
// there is a side effect I'm not seeing.
// defer container.stdin.Close()
if container.State.IsRunning() {
t.Errorf("Container shouldn't be running")
}
if err := container.Start(); err != nil {
t.Fatal(err)
}
setTimeout(t, "Waiting for the container to be started timed out", 2*time.Second, func() {
for !container.State.IsRunning() {
time.Sleep(10 * time.Millisecond)
}
})
setTimeout(t, "read/write assertion timed out", 2*time.Second, func() {
out, _ := container.StdoutPipe()
in, _ := container.StdinPipe()
if err := assertPipe("hello\n", "hello", out, in, 150); err != nil {
t.Fatal(err)
}
})
if err := container.Kill(); err != nil {
t.Fatal(err)
}
if container.State.IsRunning() {
t.Errorf("Container shouldn't be running")
}
container.State.WaitStop(-1 * time.Second)
if container.State.IsRunning() {
t.Errorf("Container shouldn't be running")
}
// Try stopping twice
if err := container.Kill(); err != nil {
t.Fatal(err)
}
}
func TestRestartStdin(t *testing.T) {
daemon := mkDaemon(t)
defer nuke(daemon)