mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Created tests for stdin pipes and tty handling
This commit is contained in:
parent
94b1cf4be3
commit
ca40989e45
1 changed files with 72 additions and 3 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue