mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Move TestRunDetach to integration-cli
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
parent
24df333fa5
commit
f7538c77ef
3 changed files with 81 additions and 51 deletions
|
@ -3,6 +3,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
@ -201,3 +202,73 @@ func TestRunDeviceDirectory(t *testing.T) {
|
|||
|
||||
logDone("run - test --device directory mounts all internal devices")
|
||||
}
|
||||
|
||||
// TestRunDetach checks attaching and detaching with the escape sequence.
|
||||
func TestRunAttachDetach(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
name := "attach-detach"
|
||||
cmd := exec.Command(dockerBinary, "run", "--name", name, "-it", "busybox", "cat")
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cpty, tty, err := pty.Open()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer cpty.Close()
|
||||
cmd.Stdin = tty
|
||||
if err := cmd.Start(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := waitRun(name); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := cpty.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)
|
||||
}
|
||||
|
||||
// escape sequence
|
||||
if _, err := cpty.Write([]byte{16}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
if _, err := cpty.Write([]byte{17}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ch := make(chan struct{})
|
||||
go func() {
|
||||
cmd.Wait()
|
||||
ch <- struct{}{}
|
||||
}()
|
||||
|
||||
running, err := inspectField(name, "State.Running")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if running != "true" {
|
||||
t.Fatal("exepected container to still be running")
|
||||
}
|
||||
|
||||
go func() {
|
||||
dockerCmd(t, "kill", name)
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-ch:
|
||||
case <-time.After(10 * time.Millisecond):
|
||||
t.Fatal("timed out waiting for container to exit")
|
||||
}
|
||||
|
||||
logDone("run - attach detach")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue