mirror of https://github.com/docker/docs.git
Created tests for stdin pipes and tty handling
This commit is contained in:
parent
94b1cf4be3
commit
ca40989e45
|
@ -2,6 +2,8 @@ package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -88,9 +90,6 @@ func TestOutput(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer docker.Destroy(container)
|
defer docker.Destroy(container)
|
||||||
|
|
||||||
pipe, err := container.StdoutPipe()
|
|
||||||
defer pipe.Close()
|
|
||||||
output, err := container.Output()
|
output, err := container.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
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) {
|
func BenchmarkRunSequencial(b *testing.B) {
|
||||||
docker, err := newTestDocker()
|
docker, err := newTestDocker()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue