mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge remote-tracking branch 'origin/improve_container_tests'
This commit is contained in:
commit
7dbb1eacc1
1 changed files with 100 additions and 32 deletions
|
@ -201,17 +201,33 @@ func TestCommitRun(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer runtime.Destroy(container2)
|
defer runtime.Destroy(container2)
|
||||||
stdout, err := container2.StdoutPipe()
|
stdout, err := container2.StdoutPipe()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
stderr, err := container2.StderrPipe()
|
stderr, err := container2.StderrPipe()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
if err := container2.Start(); err != nil {
|
if err := container2.Start(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
container2.Wait()
|
container2.Wait()
|
||||||
output, err := ioutil.ReadAll(stdout)
|
output, err := ioutil.ReadAll(stdout)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
output2, err := ioutil.ReadAll(stderr)
|
output2, err := ioutil.ReadAll(stderr)
|
||||||
stdout.Close()
|
if err != nil {
|
||||||
stderr.Close()
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := stdout.Close(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := stderr.Close(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
if string(output) != "hello\n" {
|
if string(output) != "hello\n" {
|
||||||
t.Fatalf("\nout: %s\nerr: %s\n", string(output), string(output2))
|
t.Fatalf("Unexpected output. Expected %s, received: %s (err: %s)", "hello\n", string(output), string(output2))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,11 +334,9 @@ func TestExitCode(t *testing.T) {
|
||||||
defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
|
|
||||||
trueContainer, err := runtime.Create(&Config{
|
trueContainer, err := runtime.Create(&Config{
|
||||||
|
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).Id,
|
||||||
Cmd: []string{"/bin/true", ""},
|
Cmd: []string{"/bin/true", ""},
|
||||||
},
|
})
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -330,12 +344,14 @@ func TestExitCode(t *testing.T) {
|
||||||
if err := trueContainer.Run(); err != nil {
|
if err := trueContainer.Run(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
if trueContainer.State.ExitCode != 0 {
|
||||||
|
t.Errorf("Unexpected exit code %d (expected 0)", trueContainer.State.ExitCode)
|
||||||
|
}
|
||||||
|
|
||||||
falseContainer, err := runtime.Create(&Config{
|
falseContainer, err := runtime.Create(&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).Id,
|
||||||
Cmd: []string{"/bin/false", ""},
|
Cmd: []string{"/bin/false", ""},
|
||||||
},
|
})
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -343,13 +359,8 @@ func TestExitCode(t *testing.T) {
|
||||||
if err := falseContainer.Run(); err != nil {
|
if err := falseContainer.Run(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if trueContainer.State.ExitCode != 0 {
|
|
||||||
t.Errorf("Unexpected exit code %v", trueContainer.State.ExitCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
if falseContainer.State.ExitCode != 1 {
|
if falseContainer.State.ExitCode != 1 {
|
||||||
t.Errorf("Unexpected exit code %v", falseContainer.State.ExitCode)
|
t.Errorf("Unexpected exit code %d (expected 1)", falseContainer.State.ExitCode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,32 +416,62 @@ func TestRestartStdin(t *testing.T) {
|
||||||
defer runtime.Destroy(container)
|
defer runtime.Destroy(container)
|
||||||
|
|
||||||
stdin, err := container.StdinPipe()
|
stdin, err := container.StdinPipe()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
stdout, err := container.StdoutPipe()
|
stdout, err := container.StdoutPipe()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
if err := container.Start(); err != nil {
|
if err := container.Start(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
io.WriteString(stdin, "hello world")
|
if _, err := io.WriteString(stdin, "hello world"); err != nil {
|
||||||
stdin.Close()
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := stdin.Close(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
container.Wait()
|
container.Wait()
|
||||||
output, err := ioutil.ReadAll(stdout)
|
output, err := ioutil.ReadAll(stdout)
|
||||||
stdout.Close()
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := stdout.Close(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
if string(output) != "hello world" {
|
if string(output) != "hello world" {
|
||||||
t.Fatal(string(output))
|
t.Fatalf("Unexpected output. Expected %s, received: %s", "hello world", string(output))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restart and try again
|
// Restart and try again
|
||||||
stdin, err = container.StdinPipe()
|
stdin, err = container.StdinPipe()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
stdout, err = container.StdoutPipe()
|
stdout, err = container.StdoutPipe()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
if err := container.Start(); err != nil {
|
if err := container.Start(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
io.WriteString(stdin, "hello world #2")
|
if _, err := io.WriteString(stdin, "hello world #2"); err != nil {
|
||||||
stdin.Close()
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := stdin.Close(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
container.Wait()
|
container.Wait()
|
||||||
output, err = ioutil.ReadAll(stdout)
|
output, err = ioutil.ReadAll(stdout)
|
||||||
stdout.Close()
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := stdout.Close(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
if string(output) != "hello world #2" {
|
if string(output) != "hello world #2" {
|
||||||
t.Fatal(string(output))
|
t.Fatalf("Unexpected output. Expected %s, received: %s", "hello world #2", string(output))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -614,18 +655,31 @@ func TestStdin(t *testing.T) {
|
||||||
defer runtime.Destroy(container)
|
defer runtime.Destroy(container)
|
||||||
|
|
||||||
stdin, err := container.StdinPipe()
|
stdin, err := container.StdinPipe()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
stdout, err := container.StdoutPipe()
|
stdout, err := container.StdoutPipe()
|
||||||
defer stdin.Close()
|
if err != nil {
|
||||||
defer stdout.Close()
|
t.Fatal(err)
|
||||||
|
}
|
||||||
if err := container.Start(); err != nil {
|
if err := container.Start(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
io.WriteString(stdin, "hello world")
|
defer stdin.Close()
|
||||||
stdin.Close()
|
defer stdout.Close()
|
||||||
|
if _, err := io.WriteString(stdin, "hello world"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := stdin.Close(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
container.Wait()
|
container.Wait()
|
||||||
output, err := ioutil.ReadAll(stdout)
|
output, err := ioutil.ReadAll(stdout)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
if string(output) != "hello world" {
|
if string(output) != "hello world" {
|
||||||
t.Fatal(string(output))
|
t.Fatalf("Unexpected output. Expected %s, received: %s", "hello world", string(output))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -648,18 +702,31 @@ func TestTty(t *testing.T) {
|
||||||
defer runtime.Destroy(container)
|
defer runtime.Destroy(container)
|
||||||
|
|
||||||
stdin, err := container.StdinPipe()
|
stdin, err := container.StdinPipe()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
stdout, err := container.StdoutPipe()
|
stdout, err := container.StdoutPipe()
|
||||||
defer stdin.Close()
|
if err != nil {
|
||||||
defer stdout.Close()
|
t.Fatal(err)
|
||||||
|
}
|
||||||
if err := container.Start(); err != nil {
|
if err := container.Start(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
io.WriteString(stdin, "hello world")
|
defer stdin.Close()
|
||||||
stdin.Close()
|
defer stdout.Close()
|
||||||
|
if _, err := io.WriteString(stdin, "hello world"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := stdin.Close(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
container.Wait()
|
container.Wait()
|
||||||
output, err := ioutil.ReadAll(stdout)
|
output, err := ioutil.ReadAll(stdout)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
if string(output) != "hello world" {
|
if string(output) != "hello world" {
|
||||||
t.Fatal(string(output))
|
t.Fatalf("Unexpected output. Expected %s, received: %s", "hello world", string(output))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -678,6 +745,7 @@ func TestEnv(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer runtime.Destroy(container)
|
defer runtime.Destroy(container)
|
||||||
|
|
||||||
stdout, err := container.StdoutPipe()
|
stdout, err := container.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue