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

@ -3,18 +3,18 @@ package main
import (
"os/exec"
"strings"
"testing"
"time"
"github.com/go-check/check"
)
// non-blocking wait with 0 exit code
func TestWaitNonBlockedExitZero(t *testing.T) {
defer deleteAllContainers()
func (s *DockerSuite) TestWaitNonBlockedExitZero(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "true")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
t.Fatal(out, err)
c.Fatal(out, err)
}
containerID := strings.TrimSpace(out)
@ -23,13 +23,13 @@ func TestWaitNonBlockedExitZero(t *testing.T) {
runCmd = exec.Command(dockerBinary, "inspect", "--format='{{.State.Running}}'", containerID)
status, _, err = runCommandWithOutput(runCmd)
if err != nil {
t.Fatal(status, err)
c.Fatal(status, err)
}
status = strings.TrimSpace(status)
time.Sleep(time.Second)
if i >= 60 {
t.Fatal("Container should have stopped by now")
c.Fatal("Container should have stopped by now")
}
}
@ -37,20 +37,18 @@ func TestWaitNonBlockedExitZero(t *testing.T) {
out, _, err = runCommandWithOutput(runCmd)
if err != nil || strings.TrimSpace(out) != "0" {
t.Fatal("failed to set up container", out, err)
c.Fatal("failed to set up container", out, err)
}
logDone("wait - non-blocking wait with 0 exit code")
}
// blocking wait with 0 exit code
func TestWaitBlockedExitZero(t *testing.T) {
defer deleteAllContainers()
func (s *DockerSuite) TestWaitBlockedExitZero(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "sleep 10")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
t.Fatal(out, err)
c.Fatal(out, err)
}
containerID := strings.TrimSpace(out)
@ -58,20 +56,18 @@ func TestWaitBlockedExitZero(t *testing.T) {
out, _, err = runCommandWithOutput(runCmd)
if err != nil || strings.TrimSpace(out) != "0" {
t.Fatal("failed to set up container", out, err)
c.Fatal("failed to set up container", out, err)
}
logDone("wait - blocking wait with 0 exit code")
}
// non-blocking wait with random exit code
func TestWaitNonBlockedExitRandom(t *testing.T) {
defer deleteAllContainers()
func (s *DockerSuite) TestWaitNonBlockedExitRandom(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "exit 99")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
t.Fatal(out, err)
c.Fatal(out, err)
}
containerID := strings.TrimSpace(out)
@ -80,13 +76,13 @@ func TestWaitNonBlockedExitRandom(t *testing.T) {
runCmd = exec.Command(dockerBinary, "inspect", "--format='{{.State.Running}}'", containerID)
status, _, err = runCommandWithOutput(runCmd)
if err != nil {
t.Fatal(status, err)
c.Fatal(status, err)
}
status = strings.TrimSpace(status)
time.Sleep(time.Second)
if i >= 60 {
t.Fatal("Container should have stopped by now")
c.Fatal("Container should have stopped by now")
}
}
@ -94,20 +90,18 @@ func TestWaitNonBlockedExitRandom(t *testing.T) {
out, _, err = runCommandWithOutput(runCmd)
if err != nil || strings.TrimSpace(out) != "99" {
t.Fatal("failed to set up container", out, err)
c.Fatal("failed to set up container", out, err)
}
logDone("wait - non-blocking wait with random exit code")
}
// blocking wait with random exit code
func TestWaitBlockedExitRandom(t *testing.T) {
defer deleteAllContainers()
func (s *DockerSuite) TestWaitBlockedExitRandom(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "sh", "-c", "sleep 10; exit 99")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
t.Fatal(out, err)
c.Fatal(out, err)
}
containerID := strings.TrimSpace(out)
@ -115,8 +109,7 @@ func TestWaitBlockedExitRandom(t *testing.T) {
out, _, err = runCommandWithOutput(runCmd)
if err != nil || strings.TrimSpace(out) != "99" {
t.Fatal("failed to set up container", out, err)
c.Fatal("failed to set up container", out, err)
}
logDone("wait - blocking wait with random exit code")
}