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

@ -8,17 +8,17 @@ import (
"os"
"os/exec"
"strings"
"testing"
"github.com/docker/docker/vendor/src/github.com/kr/pty"
"github.com/go-check/check"
)
// save a repo and try to load it using stdout
func TestSaveAndLoadRepoStdout(t *testing.T) {
func (s *DockerSuite) TestSaveAndLoadRepoStdout(c *check.C) {
runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
out, _, err := runCommandWithOutput(runCmd)
if err != nil {
t.Fatalf("failed to create a container: %s, %v", out, err)
c.Fatalf("failed to create a container: %s, %v", out, err)
}
cleanedContainerID := strings.TrimSpace(out)
@ -27,25 +27,25 @@ func TestSaveAndLoadRepoStdout(t *testing.T) {
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID)
if out, _, err = runCommandWithOutput(inspectCmd); err != nil {
t.Fatalf("output should've been a container id: %s, %v", out, err)
c.Fatalf("output should've been a container id: %s, %v", out, err)
}
commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID, repoName)
if out, _, err = runCommandWithOutput(commitCmd); err != nil {
t.Fatalf("failed to commit container: %s, %v", out, err)
c.Fatalf("failed to commit container: %s, %v", out, err)
}
inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
before, _, err := runCommandWithOutput(inspectCmd)
if err != nil {
t.Fatalf("the repo should exist before saving it: %s, %v", before, err)
c.Fatalf("the repo should exist before saving it: %s, %v", before, err)
}
saveCmdTemplate := `%v save %v > /tmp/foobar-save-load-test.tar`
saveCmdFinal := fmt.Sprintf(saveCmdTemplate, dockerBinary, repoName)
saveCmd := exec.Command("bash", "-c", saveCmdFinal)
if out, _, err = runCommandWithOutput(saveCmd); err != nil {
t.Fatalf("failed to save repo: %s, %v", out, err)
c.Fatalf("failed to save repo: %s, %v", out, err)
}
deleteImages(repoName)
@ -53,17 +53,17 @@ func TestSaveAndLoadRepoStdout(t *testing.T) {
loadCmdFinal := `cat /tmp/foobar-save-load-test.tar | docker load`
loadCmd := exec.Command("bash", "-c", loadCmdFinal)
if out, _, err = runCommandWithOutput(loadCmd); err != nil {
t.Fatalf("failed to load repo: %s, %v", out, err)
c.Fatalf("failed to load repo: %s, %v", out, err)
}
inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
after, _, err := runCommandWithOutput(inspectCmd)
if err != nil {
t.Fatalf("the repo should exist after loading it: %s %v", after, err)
c.Fatalf("the repo should exist after loading it: %s %v", after, err)
}
if before != after {
t.Fatalf("inspect is not the same after a save / load")
c.Fatalf("inspect is not the same after a save / load")
}
deleteContainer(cleanedContainerID)
@ -73,29 +73,28 @@ func TestSaveAndLoadRepoStdout(t *testing.T) {
pty, tty, err := pty.Open()
if err != nil {
t.Fatalf("Could not open pty: %v", err)
c.Fatalf("Could not open pty: %v", err)
}
cmd := exec.Command(dockerBinary, "save", repoName)
cmd.Stdin = tty
cmd.Stdout = tty
cmd.Stderr = tty
if err := cmd.Start(); err != nil {
t.Fatalf("start err: %v", err)
c.Fatalf("start err: %v", err)
}
if err := cmd.Wait(); err == nil {
t.Fatal("did not break writing to a TTY")
c.Fatal("did not break writing to a TTY")
}
buf := make([]byte, 1024)
n, err := pty.Read(buf)
if err != nil {
t.Fatal("could not read tty output")
c.Fatal("could not read tty output")
}
if !bytes.Contains(buf[:n], []byte("Cowardly refusing")) {
t.Fatal("help output is not being yielded", out)
c.Fatal("help output is not being yielded", out)
}
logDone("save - save/load a repo using stdout")
}