Reenable CmdRunAttachStdin and CmdRunHostname now using the DockConn interface
This commit is contained in:
parent
b71b226cc1
commit
bdf05d8368
143
commands_test.go
143
commands_test.go
|
@ -2,11 +2,10 @@ package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
_ "bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/rcli"
|
"github.com/dotcloud/docker/rcli"
|
||||||
"io"
|
"io"
|
||||||
_ "io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -62,23 +61,35 @@ func assertPipe(input, output string, r io.Reader, w io.Writer, count int) error
|
||||||
|
|
||||||
// TestRunHostname checks that 'docker run -h' correctly sets a custom hostname
|
// TestRunHostname checks that 'docker run -h' correctly sets a custom hostname
|
||||||
func TestRunHostname(t *testing.T) {
|
func TestRunHostname(t *testing.T) {
|
||||||
// runtime, err := newTestRuntime()
|
runtime, err := newTestRuntime()
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// t.Fatal(err)
|
t.Fatal(err)
|
||||||
// }
|
}
|
||||||
// defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
|
|
||||||
// srv := &Server{runtime: runtime}
|
srv := &Server{runtime: runtime}
|
||||||
|
|
||||||
// var stdin, stdout bytes.Buffer
|
stdin, _ := io.Pipe()
|
||||||
// setTimeout(t, "CmdRun timed out", 2*time.Second, func() {
|
stdout, stdoutPipe := io.Pipe()
|
||||||
// if err := srv.CmdRun(ioutil.NopCloser(&stdin), &nopWriteCloser{&stdout}, "-h", "foobar", GetTestImage(runtime).Id, "hostname"); err != nil {
|
|
||||||
// t.Fatal(err)
|
c := make(chan struct{})
|
||||||
// }
|
go func() {
|
||||||
// })
|
if err := srv.CmdRun(stdin, rcli.NewDockerLocalConn(stdoutPipe), "-h", "foobar", GetTestImage(runtime).Id, "hostname"); err != nil {
|
||||||
// if output := string(stdout.Bytes()); output != "foobar\n" {
|
t.Fatal(err)
|
||||||
// t.Fatalf("'hostname' should display '%s', not '%s'", "foobar\n", output)
|
}
|
||||||
// }
|
close(c)
|
||||||
|
}()
|
||||||
|
cmdOutput, err := bufio.NewReader(stdout).ReadString('\n')
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if cmdOutput != "foobar\n" {
|
||||||
|
t.Fatalf("'hostname' should display '%s', not '%s'", "foobar\n", cmdOutput)
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(t, "CmdRun timed out", 2*time.Second, func() {
|
||||||
|
<-c
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunExit(t *testing.T) {
|
func TestRunExit(t *testing.T) {
|
||||||
|
@ -183,56 +194,66 @@ func TestRunDisconnect(t *testing.T) {
|
||||||
// TestAttachStdin checks attaching to stdin without stdout and stderr.
|
// TestAttachStdin checks attaching to stdin without stdout and stderr.
|
||||||
// 'docker run -i -a stdin' should sends the client's stdin to the command,
|
// 'docker run -i -a stdin' should sends the client's stdin to the command,
|
||||||
// then detach from it and print the container id.
|
// then detach from it and print the container id.
|
||||||
func TestAttachStdin(t *testing.T) {
|
func TestRunAttachStdin(t *testing.T) {
|
||||||
// runtime, err := newTestRuntime()
|
runtime, err := newTestRuntime()
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// t.Fatal(err)
|
t.Fatal(err)
|
||||||
// }
|
}
|
||||||
// defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
// srv := &Server{runtime: runtime}
|
srv := &Server{runtime: runtime}
|
||||||
|
|
||||||
// stdinR, stdinW := io.Pipe()
|
stdin, stdinPipe := io.Pipe()
|
||||||
// var stdout bytes.Buffer
|
stdout, stdoutPipe := io.Pipe()
|
||||||
|
|
||||||
// ch := make(chan struct{})
|
ch := make(chan struct{})
|
||||||
// go func() {
|
go func() {
|
||||||
// srv.CmdRun(stdinR, &stdout, "-i", "-a", "stdin", GetTestImage(runtime).Id, "sh", "-c", "echo hello; cat")
|
srv.CmdRun(stdin, rcli.NewDockerLocalConn(stdoutPipe), "-i", "-a", "stdin", GetTestImage(runtime).Id, "sh", "-c", "echo hello; cat")
|
||||||
// close(ch)
|
close(ch)
|
||||||
// }()
|
}()
|
||||||
|
|
||||||
// // Send input to the command, close stdin, wait for CmdRun to return
|
// Send input to the command, close stdin
|
||||||
// setTimeout(t, "Read/Write timed out", 2*time.Second, func() {
|
setTimeout(t, "Write timed out", 2*time.Second, func() {
|
||||||
// if _, err := stdinW.Write([]byte("hi there\n")); err != nil {
|
if _, err := stdinPipe.Write([]byte("hi there\n")); err != nil {
|
||||||
// t.Fatal(err)
|
t.Fatal(err)
|
||||||
// }
|
}
|
||||||
// stdinW.Close()
|
if err := stdinPipe.Close(); err != nil {
|
||||||
// <-ch
|
t.Fatal(err)
|
||||||
// })
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// // Check output
|
container := runtime.List()[0]
|
||||||
// cmdOutput := string(stdout.Bytes())
|
|
||||||
// container := runtime.List()[0]
|
|
||||||
// if cmdOutput != container.ShortId()+"\n" {
|
|
||||||
// t.Fatalf("Wrong output: should be '%s', not '%s'\n", container.ShortId()+"\n", cmdOutput)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// setTimeout(t, "Waiting for command to exit timed out", 2*time.Second, func() {
|
// Check output
|
||||||
// container.Wait()
|
cmdOutput, err := bufio.NewReader(stdout).ReadString('\n')
|
||||||
// })
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if cmdOutput != container.ShortId()+"\n" {
|
||||||
|
t.Fatalf("Wrong output: should be '%s', not '%s'\n", container.ShortId()+"\n", cmdOutput)
|
||||||
|
}
|
||||||
|
|
||||||
// // Check logs
|
// wait for CmdRun to return
|
||||||
// if cmdLogs, err := container.ReadLog("stdout"); err != nil {
|
setTimeout(t, "Waiting for CmdRun timed out", 2*time.Second, func() {
|
||||||
// t.Fatal(err)
|
<-ch
|
||||||
// } else {
|
})
|
||||||
// if output, err := ioutil.ReadAll(cmdLogs); err != nil {
|
|
||||||
// t.Fatal(err)
|
setTimeout(t, "Waiting for command to exit timed out", 2*time.Second, func() {
|
||||||
// } else {
|
container.Wait()
|
||||||
// expectedLog := "hello\nhi there\n"
|
})
|
||||||
// if string(output) != expectedLog {
|
|
||||||
// t.Fatalf("Unexpected logs: should be '%s', not '%s'\n", expectedLog, output)
|
// Check logs
|
||||||
// }
|
if cmdLogs, err := container.ReadLog("stdout"); err != nil {
|
||||||
// }
|
t.Fatal(err)
|
||||||
// }
|
} else {
|
||||||
|
if output, err := ioutil.ReadAll(cmdLogs); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
} else {
|
||||||
|
expectedLog := "hello\nhi there\n"
|
||||||
|
if string(output) != expectedLog {
|
||||||
|
t.Fatalf("Unexpected logs: should be '%s', not '%s'\n", expectedLog, output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expected behaviour, the process stays alive when the client disconnects
|
// Expected behaviour, the process stays alive when the client disconnects
|
||||||
|
|
Loading…
Reference in New Issue