1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Use suite for integration-cli

It prints test name and duration for each test.
Also performs deleteAllContainers after each test.

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
Alexander Morozov 2015-04-18 09:46:47 -07:00
parent 6dcdf832a3
commit dc944ea7e4
60 changed files with 3746 additions and 4807 deletions

View file

@ -6,14 +6,14 @@ import (
"os/exec"
"strings"
"sync"
"testing"
"time"
"github.com/go-check/check"
)
const attachWait = 5 * time.Second
func TestAttachMultipleAndRestart(t *testing.T) {
defer deleteAllContainers()
func (s *DockerSuite) TestAttachMultipleAndRestart(c *check.C) {
endGroup := &sync.WaitGroup{}
startGroup := &sync.WaitGroup{}
@ -21,7 +21,7 @@ func TestAttachMultipleAndRestart(t *testing.T) {
startGroup.Add(3)
if err := waitForContainer("attacher", "-d", "busybox", "/bin/sh", "-c", "while true; do sleep 1; echo hello; done"); err != nil {
t.Fatal(err)
c.Fatal(err)
}
startDone := make(chan struct{})
@ -39,32 +39,32 @@ func TestAttachMultipleAndRestart(t *testing.T) {
for i := 0; i < 3; i++ {
go func() {
c := exec.Command(dockerBinary, "attach", "attacher")
cmd := exec.Command(dockerBinary, "attach", "attacher")
defer func() {
c.Wait()
cmd.Wait()
endGroup.Done()
}()
out, err := c.StdoutPipe()
out, err := cmd.StdoutPipe()
if err != nil {
t.Fatal(err)
c.Fatal(err)
}
if err := c.Start(); err != nil {
t.Fatal(err)
if err := cmd.Start(); err != nil {
c.Fatal(err)
}
buf := make([]byte, 1024)
if _, err := out.Read(buf); err != nil && err != io.EOF {
t.Fatal(err)
c.Fatal(err)
}
startGroup.Done()
if !strings.Contains(string(buf), "hello") {
t.Fatalf("unexpected output %s expected hello\n", string(buf))
c.Fatalf("unexpected output %s expected hello\n", string(buf))
}
}()
}
@ -72,41 +72,39 @@ func TestAttachMultipleAndRestart(t *testing.T) {
select {
case <-startDone:
case <-time.After(attachWait):
t.Fatalf("Attaches did not initialize properly")
c.Fatalf("Attaches did not initialize properly")
}
cmd := exec.Command(dockerBinary, "kill", "attacher")
if _, err := runCommand(cmd); err != nil {
t.Fatal(err)
c.Fatal(err)
}
select {
case <-endDone:
case <-time.After(attachWait):
t.Fatalf("Attaches did not finish properly")
c.Fatalf("Attaches did not finish properly")
}
logDone("attach - multiple attach")
}
func TestAttachTtyWithoutStdin(t *testing.T) {
defer deleteAllContainers()
func (s *DockerSuite) TestAttachTtyWithoutStdin(c *check.C) {
cmd := exec.Command(dockerBinary, "run", "-d", "-ti", "busybox")
out, _, err := runCommandWithOutput(cmd)
if err != nil {
t.Fatalf("failed to start container: %v (%v)", out, err)
c.Fatalf("failed to start container: %v (%v)", out, err)
}
id := strings.TrimSpace(out)
if err := waitRun(id); err != nil {
t.Fatal(err)
c.Fatal(err)
}
defer func() {
cmd := exec.Command(dockerBinary, "kill", id)
if out, _, err := runCommandWithOutput(cmd); err != nil {
t.Fatalf("failed to kill container: %v (%v)", out, err)
c.Fatalf("failed to kill container: %v (%v)", out, err)
}
}()
@ -116,70 +114,67 @@ func TestAttachTtyWithoutStdin(t *testing.T) {
cmd := exec.Command(dockerBinary, "attach", id)
if _, err := cmd.StdinPipe(); err != nil {
t.Fatal(err)
c.Fatal(err)
}
expected := "cannot enable tty mode"
if out, _, err := runCommandWithOutput(cmd); err == nil {
t.Fatal("attach should have failed")
c.Fatal("attach should have failed")
} else if !strings.Contains(out, expected) {
t.Fatalf("attach failed with error %q: expected %q", out, expected)
c.Fatalf("attach failed with error %q: expected %q", out, expected)
}
}()
select {
case <-done:
case <-time.After(attachWait):
t.Fatal("attach is running but should have failed")
c.Fatal("attach is running but should have failed")
}
logDone("attach - forbid piped stdin to tty enabled container")
}
func TestAttachDisconnect(t *testing.T) {
defer deleteAllContainers()
out, _ := dockerCmd(t, "run", "-di", "busybox", "/bin/cat")
func (s *DockerSuite) TestAttachDisconnect(c *check.C) {
out, _ := dockerCmd(c, "run", "-di", "busybox", "/bin/cat")
id := strings.TrimSpace(out)
cmd := exec.Command(dockerBinary, "attach", id)
stdin, err := cmd.StdinPipe()
if err != nil {
t.Fatal(err)
c.Fatal(err)
}
defer stdin.Close()
stdout, err := cmd.StdoutPipe()
if err != nil {
t.Fatal(err)
c.Fatal(err)
}
defer stdout.Close()
if err := cmd.Start(); err != nil {
t.Fatal(err)
c.Fatal(err)
}
defer cmd.Process.Kill()
if _, err := stdin.Write([]byte("hello\n")); err != nil {
t.Fatal(err)
c.Fatal(err)
}
out, err = bufio.NewReader(stdout).ReadString('\n')
if err != nil {
t.Fatal(err)
c.Fatal(err)
}
if strings.TrimSpace(out) != "hello" {
t.Fatalf("exepected 'hello', got %q", out)
c.Fatalf("exepected 'hello', got %q", out)
}
if err := stdin.Close(); err != nil {
t.Fatal(err)
c.Fatal(err)
}
// Expect container to still be running after stdin is closed
running, err := inspectField(id, "State.Running")
if err != nil {
t.Fatal(err)
c.Fatal(err)
}
if running != "true" {
t.Fatal("exepected container to still be running")
c.Fatal("exepected container to still be running")
}
logDone("attach - disconnect")
}