Signed-off-by: Victor Vieux <vieux@docker.com>
| ... | ... |
@@ -34,3 +34,31 @@ func TestKillContainer(t *testing.T) {
|
| 34 | 34 |
|
| 35 | 35 |
logDone("kill - kill container running sleep 10")
|
| 36 | 36 |
} |
| 37 |
+ |
|
| 38 |
+func TestKillDifferentUserContainer(t *testing.T) {
|
|
| 39 |
+ runCmd := exec.Command(dockerBinary, "run", "-u", "daemon", "-d", "busybox", "sh", "-c", "sleep 10") |
|
| 40 |
+ out, _, err := runCommandWithOutput(runCmd) |
|
| 41 |
+ errorOut(err, t, fmt.Sprintf("run failed with errors: %v", err))
|
|
| 42 |
+ |
|
| 43 |
+ cleanedContainerID := stripTrailingCharacters(out) |
|
| 44 |
+ |
|
| 45 |
+ inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID) |
|
| 46 |
+ inspectOut, _, err := runCommandWithOutput(inspectCmd) |
|
| 47 |
+ errorOut(err, t, fmt.Sprintf("out should've been a container id: %v %v", inspectOut, err))
|
|
| 48 |
+ |
|
| 49 |
+ killCmd := exec.Command(dockerBinary, "kill", cleanedContainerID) |
|
| 50 |
+ out, _, err = runCommandWithOutput(killCmd) |
|
| 51 |
+ errorOut(err, t, fmt.Sprintf("failed to kill container: %v %v", out, err))
|
|
| 52 |
+ |
|
| 53 |
+ listRunningContainersCmd := exec.Command(dockerBinary, "ps", "-q") |
|
| 54 |
+ out, _, err = runCommandWithOutput(listRunningContainersCmd) |
|
| 55 |
+ errorOut(err, t, fmt.Sprintf("failed to list running containers: %v", err))
|
|
| 56 |
+ |
|
| 57 |
+ if strings.Contains(out, cleanedContainerID) {
|
|
| 58 |
+ t.Fatal("killed container is still running")
|
|
| 59 |
+ } |
|
| 60 |
+ |
|
| 61 |
+ deleteContainer(cleanedContainerID) |
|
| 62 |
+ |
|
| 63 |
+ logDone("kill - kill container running sleep 10 from a different user")
|
|
| 64 |
+} |
| ... | ... |
@@ -13,64 +13,6 @@ import ( |
| 13 | 13 |
"github.com/docker/docker/runconfig" |
| 14 | 14 |
) |
| 15 | 15 |
|
| 16 |
-func TestKillDifferentUser(t *testing.T) {
|
|
| 17 |
- daemon := mkDaemon(t) |
|
| 18 |
- defer nuke(daemon) |
|
| 19 |
- |
|
| 20 |
- container, _, err := daemon.Create(&runconfig.Config{
|
|
| 21 |
- Image: GetTestImage(daemon).ID, |
|
| 22 |
- Cmd: []string{"cat"},
|
|
| 23 |
- OpenStdin: true, |
|
| 24 |
- User: "daemon", |
|
| 25 |
- }, |
|
| 26 |
- "", |
|
| 27 |
- ) |
|
| 28 |
- if err != nil {
|
|
| 29 |
- t.Fatal(err) |
|
| 30 |
- } |
|
| 31 |
- defer daemon.Destroy(container) |
|
| 32 |
- // FIXME @shykes: this seems redundant, but is very old, I'm leaving it in case |
|
| 33 |
- // there is a side effect I'm not seeing. |
|
| 34 |
- // defer container.stdin.Close() |
|
| 35 |
- |
|
| 36 |
- if container.State.IsRunning() {
|
|
| 37 |
- t.Errorf("Container shouldn't be running")
|
|
| 38 |
- } |
|
| 39 |
- if err := container.Start(); err != nil {
|
|
| 40 |
- t.Fatal(err) |
|
| 41 |
- } |
|
| 42 |
- |
|
| 43 |
- setTimeout(t, "Waiting for the container to be started timed out", 2*time.Second, func() {
|
|
| 44 |
- for !container.State.IsRunning() {
|
|
| 45 |
- time.Sleep(10 * time.Millisecond) |
|
| 46 |
- } |
|
| 47 |
- }) |
|
| 48 |
- |
|
| 49 |
- setTimeout(t, "read/write assertion timed out", 2*time.Second, func() {
|
|
| 50 |
- out, _ := container.StdoutPipe() |
|
| 51 |
- in, _ := container.StdinPipe() |
|
| 52 |
- if err := assertPipe("hello\n", "hello", out, in, 150); err != nil {
|
|
| 53 |
- t.Fatal(err) |
|
| 54 |
- } |
|
| 55 |
- }) |
|
| 56 |
- |
|
| 57 |
- if err := container.Kill(); err != nil {
|
|
| 58 |
- t.Fatal(err) |
|
| 59 |
- } |
|
| 60 |
- |
|
| 61 |
- if container.State.IsRunning() {
|
|
| 62 |
- t.Errorf("Container shouldn't be running")
|
|
| 63 |
- } |
|
| 64 |
- container.State.WaitStop(-1 * time.Second) |
|
| 65 |
- if container.State.IsRunning() {
|
|
| 66 |
- t.Errorf("Container shouldn't be running")
|
|
| 67 |
- } |
|
| 68 |
- // Try stopping twice |
|
| 69 |
- if err := container.Kill(); err != nil {
|
|
| 70 |
- t.Fatal(err) |
|
| 71 |
- } |
|
| 72 |
-} |
|
| 73 |
- |
|
| 74 | 16 |
func TestRestartStdin(t *testing.T) {
|
| 75 | 17 |
daemon := mkDaemon(t) |
| 76 | 18 |
defer nuke(daemon) |