mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00: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:
@@ -3,96 +3,94 @@ package main
|
||||
import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
func TestCommitAfterContainerIsDone(t *testing.T) {
|
||||
func (s *DockerSuite) TestCommitAfterContainerIsDone(c *check.C) {
|
||||
runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
|
||||
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to run container: %s, %v", out, err)
|
||||
c.Fatalf("failed to run container: %s, %v", out, err)
|
||||
}
|
||||
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
||||
waitCmd := exec.Command(dockerBinary, "wait", cleanedContainerID)
|
||||
if _, _, err = runCommandWithOutput(waitCmd); err != nil {
|
||||
t.Fatalf("error thrown while waiting for container: %s, %v", out, err)
|
||||
c.Fatalf("error thrown while waiting for container: %s, %v", out, err)
|
||||
}
|
||||
|
||||
commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID)
|
||||
out, _, err = runCommandWithOutput(commitCmd)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to commit container to image: %s, %v", out, err)
|
||||
c.Fatalf("failed to commit container to image: %s, %v", out, err)
|
||||
}
|
||||
|
||||
cleanedImageID := strings.TrimSpace(out)
|
||||
|
||||
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedImageID)
|
||||
if out, _, err = runCommandWithOutput(inspectCmd); err != nil {
|
||||
t.Fatalf("failed to inspect image: %s, %v", out, err)
|
||||
c.Fatalf("failed to inspect image: %s, %v", out, err)
|
||||
}
|
||||
|
||||
deleteContainer(cleanedContainerID)
|
||||
deleteImages(cleanedImageID)
|
||||
|
||||
logDone("commit - echo foo and commit the image")
|
||||
}
|
||||
|
||||
func TestCommitWithoutPause(t *testing.T) {
|
||||
func (s *DockerSuite) TestCommitWithoutPause(c *check.C) {
|
||||
runCmd := exec.Command(dockerBinary, "run", "-i", "-a", "stdin", "busybox", "echo", "foo")
|
||||
out, _, _, err := runCommandWithStdoutStderr(runCmd)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to run container: %s, %v", out, err)
|
||||
c.Fatalf("failed to run container: %s, %v", out, err)
|
||||
}
|
||||
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
||||
waitCmd := exec.Command(dockerBinary, "wait", cleanedContainerID)
|
||||
if _, _, err = runCommandWithOutput(waitCmd); err != nil {
|
||||
t.Fatalf("error thrown while waiting for container: %s, %v", out, err)
|
||||
c.Fatalf("error thrown while waiting for container: %s, %v", out, err)
|
||||
}
|
||||
|
||||
commitCmd := exec.Command(dockerBinary, "commit", "-p=false", cleanedContainerID)
|
||||
out, _, err = runCommandWithOutput(commitCmd)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to commit container to image: %s, %v", out, err)
|
||||
c.Fatalf("failed to commit container to image: %s, %v", out, err)
|
||||
}
|
||||
|
||||
cleanedImageID := strings.TrimSpace(out)
|
||||
|
||||
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedImageID)
|
||||
if out, _, err = runCommandWithOutput(inspectCmd); err != nil {
|
||||
t.Fatalf("failed to inspect image: %s, %v", out, err)
|
||||
c.Fatalf("failed to inspect image: %s, %v", out, err)
|
||||
}
|
||||
|
||||
deleteContainer(cleanedContainerID)
|
||||
deleteImages(cleanedImageID)
|
||||
|
||||
logDone("commit - echo foo and commit the image with --pause=false")
|
||||
}
|
||||
|
||||
//test commit a paused container should not unpause it after commit
|
||||
func TestCommitPausedContainer(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
func (s *DockerSuite) TestCommitPausedContainer(c *check.C) {
|
||||
defer unpauseAllContainers()
|
||||
cmd := exec.Command(dockerBinary, "run", "-i", "-d", "busybox")
|
||||
out, _, _, err := runCommandWithStdoutStderr(cmd)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to run container: %v, output: %q", err, out)
|
||||
c.Fatalf("failed to run container: %v, output: %q", err, out)
|
||||
}
|
||||
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
cmd = exec.Command(dockerBinary, "pause", cleanedContainerID)
|
||||
out, _, _, err = runCommandWithStdoutStderr(cmd)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to pause container: %v, output: %q", err, out)
|
||||
c.Fatalf("failed to pause container: %v, output: %q", err, out)
|
||||
}
|
||||
|
||||
commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID)
|
||||
out, _, err = runCommandWithOutput(commitCmd)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to commit container to image: %s, %v", out, err)
|
||||
c.Fatalf("failed to commit container to image: %s, %v", out, err)
|
||||
}
|
||||
cleanedImageID := strings.TrimSpace(out)
|
||||
defer deleteImages(cleanedImageID)
|
||||
@@ -100,28 +98,26 @@ func TestCommitPausedContainer(t *testing.T) {
|
||||
cmd = exec.Command(dockerBinary, "inspect", "-f", "{{.State.Paused}}", cleanedContainerID)
|
||||
out, _, _, err = runCommandWithStdoutStderr(cmd)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to inspect container: %v, output: %q", err, out)
|
||||
c.Fatalf("failed to inspect container: %v, output: %q", err, out)
|
||||
}
|
||||
|
||||
if !strings.Contains(out, "true") {
|
||||
t.Fatalf("commit should not unpause a paused container")
|
||||
c.Fatalf("commit should not unpause a paused container")
|
||||
}
|
||||
|
||||
logDone("commit - commit a paused container will not unpause it")
|
||||
}
|
||||
|
||||
func TestCommitNewFile(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
func (s *DockerSuite) TestCommitNewFile(c *check.C) {
|
||||
|
||||
cmd := exec.Command(dockerBinary, "run", "--name", "commiter", "busybox", "/bin/sh", "-c", "echo koye > /foo")
|
||||
if _, err := runCommand(cmd); err != nil {
|
||||
t.Fatal(err)
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
cmd = exec.Command(dockerBinary, "commit", "commiter")
|
||||
imageID, _, err := runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
c.Fatal(err)
|
||||
}
|
||||
imageID = strings.Trim(imageID, "\r\n")
|
||||
defer deleteImages(imageID)
|
||||
@@ -130,22 +126,20 @@ func TestCommitNewFile(t *testing.T) {
|
||||
|
||||
out, _, err := runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
t.Fatal(err, out)
|
||||
c.Fatal(err, out)
|
||||
}
|
||||
if actual := strings.Trim(out, "\r\n"); actual != "koye" {
|
||||
t.Fatalf("expected output koye received %q", actual)
|
||||
c.Fatalf("expected output koye received %q", actual)
|
||||
}
|
||||
|
||||
logDone("commit - commit file and read")
|
||||
}
|
||||
|
||||
func TestCommitHardlink(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
func (s *DockerSuite) TestCommitHardlink(c *check.C) {
|
||||
|
||||
cmd := exec.Command(dockerBinary, "run", "-t", "--name", "hardlinks", "busybox", "sh", "-c", "touch file1 && ln file1 file2 && ls -di file1 file2")
|
||||
firstOuput, _, err := runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
chunks := strings.Split(strings.TrimSpace(firstOuput), " ")
|
||||
@@ -158,13 +152,13 @@ func TestCommitHardlink(t *testing.T) {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:])
|
||||
c.Fatalf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:])
|
||||
}
|
||||
|
||||
cmd = exec.Command(dockerBinary, "commit", "hardlinks", "hardlinks")
|
||||
imageID, _, err := runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
t.Fatal(imageID, err)
|
||||
c.Fatal(imageID, err)
|
||||
}
|
||||
imageID = strings.Trim(imageID, "\r\n")
|
||||
defer deleteImages(imageID)
|
||||
@@ -172,7 +166,7 @@ func TestCommitHardlink(t *testing.T) {
|
||||
cmd = exec.Command(dockerBinary, "run", "-t", "hardlinks", "ls", "-di", "file1", "file2")
|
||||
secondOuput, _, err := runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
chunks = strings.Split(strings.TrimSpace(secondOuput), " ")
|
||||
@@ -185,48 +179,44 @@ func TestCommitHardlink(t *testing.T) {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:])
|
||||
c.Fatalf("Failed to create hardlink in a container. Expected to find %q in %q", inode, chunks[1:])
|
||||
}
|
||||
|
||||
logDone("commit - commit hardlinks")
|
||||
}
|
||||
|
||||
func TestCommitTTY(t *testing.T) {
|
||||
func (s *DockerSuite) TestCommitTTY(c *check.C) {
|
||||
defer deleteImages("ttytest")
|
||||
defer deleteAllContainers()
|
||||
|
||||
cmd := exec.Command(dockerBinary, "run", "-t", "--name", "tty", "busybox", "/bin/ls")
|
||||
if _, err := runCommand(cmd); err != nil {
|
||||
t.Fatal(err)
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
cmd = exec.Command(dockerBinary, "commit", "tty", "ttytest")
|
||||
imageID, _, err := runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
c.Fatal(err)
|
||||
}
|
||||
imageID = strings.Trim(imageID, "\r\n")
|
||||
|
||||
cmd = exec.Command(dockerBinary, "run", "ttytest", "/bin/ls")
|
||||
if _, err := runCommand(cmd); err != nil {
|
||||
t.Fatal(err)
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
logDone("commit - commit tty")
|
||||
}
|
||||
|
||||
func TestCommitWithHostBindMount(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
func (s *DockerSuite) TestCommitWithHostBindMount(c *check.C) {
|
||||
|
||||
cmd := exec.Command(dockerBinary, "run", "--name", "bind-commit", "-v", "/dev/null:/winning", "busybox", "true")
|
||||
if _, err := runCommand(cmd); err != nil {
|
||||
t.Fatal(err)
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
cmd = exec.Command(dockerBinary, "commit", "bind-commit", "bindtest")
|
||||
imageID, _, err := runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
t.Fatal(imageID, err)
|
||||
c.Fatal(imageID, err)
|
||||
}
|
||||
|
||||
imageID = strings.Trim(imageID, "\r\n")
|
||||
@@ -235,18 +225,16 @@ func TestCommitWithHostBindMount(t *testing.T) {
|
||||
cmd = exec.Command(dockerBinary, "run", "bindtest", "true")
|
||||
|
||||
if _, err := runCommand(cmd); err != nil {
|
||||
t.Fatal(err)
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
logDone("commit - commit bind mounted file")
|
||||
}
|
||||
|
||||
func TestCommitChange(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
func (s *DockerSuite) TestCommitChange(c *check.C) {
|
||||
|
||||
cmd := exec.Command(dockerBinary, "run", "--name", "test", "busybox", "true")
|
||||
if _, err := runCommand(cmd); err != nil {
|
||||
t.Fatal(err)
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
cmd = exec.Command(dockerBinary, "commit",
|
||||
@@ -257,7 +245,7 @@ func TestCommitChange(t *testing.T) {
|
||||
"test", "test-commit")
|
||||
imageId, _, err := runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
t.Fatal(imageId, err)
|
||||
c.Fatal(imageId, err)
|
||||
}
|
||||
imageId = strings.Trim(imageId, "\r\n")
|
||||
defer deleteImages(imageId)
|
||||
@@ -270,29 +258,27 @@ func TestCommitChange(t *testing.T) {
|
||||
for conf, value := range expected {
|
||||
res, err := inspectField(imageId, conf)
|
||||
if err != nil {
|
||||
t.Errorf("failed to get value %s, error: %s", conf, err)
|
||||
c.Errorf("failed to get value %s, error: %s", conf, err)
|
||||
}
|
||||
if res != value {
|
||||
t.Errorf("%s('%s'), expected %s", conf, res, value)
|
||||
c.Errorf("%s('%s'), expected %s", conf, res, value)
|
||||
}
|
||||
}
|
||||
|
||||
logDone("commit - commit --change")
|
||||
}
|
||||
|
||||
// TODO: commit --run is deprecated, remove this once --run is removed
|
||||
func TestCommitMergeConfigRun(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
func (s *DockerSuite) TestCommitMergeConfigRun(c *check.C) {
|
||||
name := "commit-test"
|
||||
out, _ := dockerCmd(t, "run", "-d", "-e=FOO=bar", "busybox", "/bin/sh", "-c", "echo testing > /tmp/foo")
|
||||
out, _ := dockerCmd(c, "run", "-d", "-e=FOO=bar", "busybox", "/bin/sh", "-c", "echo testing > /tmp/foo")
|
||||
id := strings.TrimSpace(out)
|
||||
|
||||
dockerCmd(t, "commit", `--run={"Cmd": ["cat", "/tmp/foo"]}`, id, "commit-test")
|
||||
dockerCmd(c, "commit", `--run={"Cmd": ["cat", "/tmp/foo"]}`, id, "commit-test")
|
||||
defer deleteImages("commit-test")
|
||||
|
||||
out, _ = dockerCmd(t, "run", "--name", name, "commit-test")
|
||||
out, _ = dockerCmd(c, "run", "--name", name, "commit-test")
|
||||
if strings.TrimSpace(out) != "testing" {
|
||||
t.Fatal("run config in commited container was not merged")
|
||||
c.Fatal("run config in commited container was not merged")
|
||||
}
|
||||
|
||||
type cfg struct {
|
||||
@@ -301,11 +287,11 @@ func TestCommitMergeConfigRun(t *testing.T) {
|
||||
}
|
||||
config1 := cfg{}
|
||||
if err := inspectFieldAndMarshall(id, "Config", &config1); err != nil {
|
||||
t.Fatal(err)
|
||||
c.Fatal(err)
|
||||
}
|
||||
config2 := cfg{}
|
||||
if err := inspectFieldAndMarshall(name, "Config", &config2); err != nil {
|
||||
t.Fatal(err)
|
||||
c.Fatal(err)
|
||||
}
|
||||
|
||||
// Env has at least PATH loaded as well here, so let's just grab the FOO one
|
||||
@@ -324,8 +310,7 @@ func TestCommitMergeConfigRun(t *testing.T) {
|
||||
}
|
||||
|
||||
if len(config1.Env) != len(config2.Env) || env1 != env2 && env2 != "" {
|
||||
t.Fatalf("expected envs to match: %v - %v", config1.Env, config2.Env)
|
||||
c.Fatalf("expected envs to match: %v - %v", config1.Env, config2.Env)
|
||||
}
|
||||
|
||||
logDone("commit - configs are merged with --run")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user