Created tests for stdin pipes and tty handling

This commit is contained in:
Andrea Luzzardi 2013-01-29 15:16:45 -08:00
parent 94b1cf4be3
commit ca40989e45
1 changed files with 72 additions and 3 deletions

View File

@ -2,6 +2,8 @@ package docker
import (
"fmt"
"io"
"io/ioutil"
"testing"
"time"
)
@ -88,9 +90,6 @@ func TestOutput(t *testing.T) {
t.Fatal(err)
}
defer docker.Destroy(container)
pipe, err := container.StdoutPipe()
defer pipe.Close()
output, err := container.Output()
if err != nil {
t.Fatal(err)
@ -243,6 +242,76 @@ func TestMultipleContainers(t *testing.T) {
}
}
func TestStdin(t *testing.T) {
docker, err := newTestDocker()
if err != nil {
t.Fatal(err)
}
container, err := docker.Create(
"stdin_test",
"cat",
[]string{},
[]string{"/var/lib/docker/images/ubuntu"},
&Config{
OpenStdin: true,
},
)
if err != nil {
t.Fatal(err)
}
defer docker.Destroy(container)
stdin, err := container.StdinPipe()
stdout, err := container.StdoutPipe()
defer stdin.Close()
defer stdout.Close()
if err := container.Start(); err != nil {
t.Fatal(err)
}
io.WriteString(stdin, "hello world")
stdin.Close()
container.Wait()
output, err := ioutil.ReadAll(stdout)
if string(output) != "hello world" {
t.Fatal(string(output))
}
}
func TestTty(t *testing.T) {
docker, err := newTestDocker()
if err != nil {
t.Fatal(err)
}
container, err := docker.Create(
"tty_test",
"cat",
[]string{},
[]string{"/var/lib/docker/images/ubuntu"},
&Config{
OpenStdin: true,
},
)
if err != nil {
t.Fatal(err)
}
defer docker.Destroy(container)
stdin, err := container.StdinPipe()
stdout, err := container.StdoutPipe()
defer stdin.Close()
defer stdout.Close()
if err := container.Start(); err != nil {
t.Fatal(err)
}
io.WriteString(stdin, "hello world")
stdin.Close()
container.Wait()
output, err := ioutil.ReadAll(stdout)
if string(output) != "hello world" {
t.Fatal(string(output))
}
}
func BenchmarkRunSequencial(b *testing.B) {
docker, err := newTestDocker()
if err != nil {