mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
MovetAttachDisconnect to integration-cli
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
parent
28cda04838
commit
e4cfd9b392
2 changed files with 49 additions and 75 deletions
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
@ -134,3 +135,51 @@ func TestAttachTtyWithoutStdin(t *testing.T) {
|
|||
|
||||
logDone("attach - forbid piped stdin to tty enabled container")
|
||||
}
|
||||
|
||||
func TestAttachDisconnect(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
out, _, _ := dockerCmd(t, "run", "-di", "busybox", "/bin/cat")
|
||||
id := strings.TrimSpace(out)
|
||||
|
||||
cmd := exec.Command(dockerBinary, "attach", id)
|
||||
stdin, err := cmd.StdinPipe()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer stdin.Close()
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer stdout.Close()
|
||||
if err := cmd.Start(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer cmd.Process.Kill()
|
||||
|
||||
if _, err := stdin.Write([]byte("hello\n")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
out, err = bufio.NewReader(stdout).ReadString('\n')
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.TrimSpace(out) != "hello" {
|
||||
t.Fatalf("exepected 'hello', got %q", out)
|
||||
}
|
||||
|
||||
if err := stdin.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Expect container to still be running after stdin is closed
|
||||
running, err := inspectField(id, "State.Running")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if running != "true" {
|
||||
t.Fatal("exepected container to still be running")
|
||||
}
|
||||
|
||||
logDone("attach - disconnect")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue