1
0
mirror of https://github.com/moby/moby.git synced 2025-12-06 07:41:18 +03: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

@@ -9,15 +9,16 @@ import (
"reflect"
"sort"
"strings"
"testing"
"github.com/go-check/check"
)
// save a repo using gz compression and try to load it using stdout
func TestSaveXzAndLoadRepoStdout(t *testing.T) {
func (s *DockerSuite) TestSaveXzAndLoadRepoStdout(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: %v %v", out, err)
c.Fatalf("failed to create a container: %v %v", out, err)
}
cleanedContainerID := strings.TrimSpace(out)
@@ -27,19 +28,19 @@ func TestSaveXzAndLoadRepoStdout(t *testing.T) {
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID)
out, _, err = runCommandWithOutput(inspectCmd)
if err != nil {
t.Fatalf("output should've been a container id: %v %v", cleanedContainerID, err)
c.Fatalf("output should've been a container id: %v %v", cleanedContainerID, err)
}
commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID, repoName)
out, _, err = runCommandWithOutput(commitCmd)
if err != nil {
t.Fatalf("failed to commit container: %v %v", out, err)
c.Fatalf("failed to commit container: %v %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: %v %v", before, err)
c.Fatalf("the repo should exist before saving it: %v %v", before, err)
}
repoTarball, _, err := runCommandPipelineWithOutput(
@@ -47,7 +48,7 @@ func TestSaveXzAndLoadRepoStdout(t *testing.T) {
exec.Command("xz", "-c"),
exec.Command("gzip", "-c"))
if err != nil {
t.Fatalf("failed to save repo: %v %v", out, err)
c.Fatalf("failed to save repo: %v %v", out, err)
}
deleteImages(repoName)
@@ -55,26 +56,25 @@ func TestSaveXzAndLoadRepoStdout(t *testing.T) {
loadCmd.Stdin = strings.NewReader(repoTarball)
out, _, err = runCommandWithOutput(loadCmd)
if err == nil {
t.Fatalf("expected error, but succeeded with no error and output: %v", out)
c.Fatalf("expected error, but succeeded with no error and output: %v", out)
}
inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
after, _, err := runCommandWithOutput(inspectCmd)
if err == nil {
t.Fatalf("the repo should not exist: %v", after)
c.Fatalf("the repo should not exist: %v", after)
}
deleteImages(repoName)
logDone("load - save a repo with xz compression & load it using stdout")
}
// save a repo using xz+gz compression and try to load it using stdout
func TestSaveXzGzAndLoadRepoStdout(t *testing.T) {
func (s *DockerSuite) TestSaveXzGzAndLoadRepoStdout(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: %v %v", out, err)
c.Fatalf("failed to create a container: %v %v", out, err)
}
cleanedContainerID := strings.TrimSpace(out)
@@ -84,19 +84,19 @@ func TestSaveXzGzAndLoadRepoStdout(t *testing.T) {
inspectCmd := exec.Command(dockerBinary, "inspect", cleanedContainerID)
out, _, err = runCommandWithOutput(inspectCmd)
if err != nil {
t.Fatalf("output should've been a container id: %v %v", cleanedContainerID, err)
c.Fatalf("output should've been a container id: %v %v", cleanedContainerID, err)
}
commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID, repoName)
out, _, err = runCommandWithOutput(commitCmd)
if err != nil {
t.Fatalf("failed to commit container: %v %v", out, err)
c.Fatalf("failed to commit container: %v %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: %v %v", before, err)
c.Fatalf("the repo should exist before saving it: %v %v", before, err)
}
out, _, err = runCommandPipelineWithOutput(
@@ -104,7 +104,7 @@ func TestSaveXzGzAndLoadRepoStdout(t *testing.T) {
exec.Command("xz", "-c"),
exec.Command("gzip", "-c"))
if err != nil {
t.Fatalf("failed to save repo: %v %v", out, err)
c.Fatalf("failed to save repo: %v %v", out, err)
}
deleteImages(repoName)
@@ -113,34 +113,33 @@ func TestSaveXzGzAndLoadRepoStdout(t *testing.T) {
loadCmd.Stdin = strings.NewReader(out)
out, _, err = runCommandWithOutput(loadCmd)
if err == nil {
t.Fatalf("expected error, but succeeded with no error and output: %v", out)
c.Fatalf("expected error, but succeeded with no error and output: %v", out)
}
inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
after, _, err := runCommandWithOutput(inspectCmd)
if err == nil {
t.Fatalf("the repo should not exist: %v", after)
c.Fatalf("the repo should not exist: %v", after)
}
deleteContainer(cleanedContainerID)
deleteImages(repoName)
logDone("load - save a repo with xz+gz compression & load it using stdout")
}
func TestSaveSingleTag(t *testing.T) {
func (s *DockerSuite) TestSaveSingleTag(c *check.C) {
repoName := "foobar-save-single-tag-test"
tagCmd := exec.Command(dockerBinary, "tag", "busybox:latest", fmt.Sprintf("%v:latest", repoName))
defer deleteImages(repoName)
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
t.Fatalf("failed to tag repo: %s, %v", out, err)
c.Fatalf("failed to tag repo: %s, %v", out, err)
}
idCmd := exec.Command(dockerBinary, "images", "-q", "--no-trunc", repoName)
out, _, err := runCommandWithOutput(idCmd)
if err != nil {
t.Fatalf("failed to get repo ID: %s, %v", out, err)
c.Fatalf("failed to get repo ID: %s, %v", out, err)
}
cleanedImageID := strings.TrimSpace(out)
@@ -149,25 +148,24 @@ func TestSaveSingleTag(t *testing.T) {
exec.Command("tar", "t"),
exec.Command("grep", "-E", fmt.Sprintf("(^repositories$|%v)", cleanedImageID)))
if err != nil {
t.Fatalf("failed to save repo with image ID and 'repositories' file: %s, %v", out, err)
c.Fatalf("failed to save repo with image ID and 'repositories' file: %s, %v", out, err)
}
logDone("save - save a specific image:tag")
}
func TestSaveImageId(t *testing.T) {
func (s *DockerSuite) TestSaveImageId(c *check.C) {
repoName := "foobar-save-image-id-test"
tagCmd := exec.Command(dockerBinary, "tag", "emptyfs:latest", fmt.Sprintf("%v:latest", repoName))
defer deleteImages(repoName)
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
t.Fatalf("failed to tag repo: %s, %v", out, err)
c.Fatalf("failed to tag repo: %s, %v", out, err)
}
idLongCmd := exec.Command(dockerBinary, "images", "-q", "--no-trunc", repoName)
out, _, err := runCommandWithOutput(idLongCmd)
if err != nil {
t.Fatalf("failed to get repo ID: %s, %v", out, err)
c.Fatalf("failed to get repo ID: %s, %v", out, err)
}
cleanedLongImageID := strings.TrimSpace(out)
@@ -175,7 +173,7 @@ func TestSaveImageId(t *testing.T) {
idShortCmd := exec.Command(dockerBinary, "images", "-q", repoName)
out, _, err = runCommandWithOutput(idShortCmd)
if err != nil {
t.Fatalf("failed to get repo short ID: %s, %v", out, err)
c.Fatalf("failed to get repo short ID: %s, %v", out, err)
}
cleanedShortImageID := strings.TrimSpace(out)
@@ -184,19 +182,19 @@ func TestSaveImageId(t *testing.T) {
tarCmd := exec.Command("tar", "t")
tarCmd.Stdin, err = saveCmd.StdoutPipe()
if err != nil {
t.Fatalf("cannot set stdout pipe for tar: %v", err)
c.Fatalf("cannot set stdout pipe for tar: %v", err)
}
grepCmd := exec.Command("grep", cleanedLongImageID)
grepCmd.Stdin, err = tarCmd.StdoutPipe()
if err != nil {
t.Fatalf("cannot set stdout pipe for grep: %v", err)
c.Fatalf("cannot set stdout pipe for grep: %v", err)
}
if err = tarCmd.Start(); err != nil {
t.Fatalf("tar failed with error: %v", err)
c.Fatalf("tar failed with error: %v", err)
}
if err = saveCmd.Start(); err != nil {
t.Fatalf("docker save failed with error: %v", err)
c.Fatalf("docker save failed with error: %v", err)
}
defer saveCmd.Wait()
defer tarCmd.Wait()
@@ -204,18 +202,17 @@ func TestSaveImageId(t *testing.T) {
out, _, err = runCommandWithOutput(grepCmd)
if err != nil {
t.Fatalf("failed to save repo with image ID: %s, %v", out, err)
c.Fatalf("failed to save repo with image ID: %s, %v", out, err)
}
logDone("save - save a image by ID")
}
// save a repo and try to load it using flags
func TestSaveAndLoadRepoFlags(t *testing.T) {
func (s *DockerSuite) TestSaveAndLoadRepoFlags(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)
@@ -225,19 +222,19 @@ func TestSaveAndLoadRepoFlags(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)
deleteImages(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)
}
@@ -245,29 +242,28 @@ func TestSaveAndLoadRepoFlags(t *testing.T) {
exec.Command(dockerBinary, "save", repoName),
exec.Command(dockerBinary, "load"))
if err != nil {
t.Fatalf("failed to save and load repo: %s, %v", out, err)
c.Fatalf("failed to save and 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")
}
logDone("save - save a repo using -o && load a repo using -i")
}
func TestSaveMultipleNames(t *testing.T) {
func (s *DockerSuite) TestSaveMultipleNames(c *check.C) {
repoName := "foobar-save-multi-name-test"
// Make one image
tagCmd := exec.Command(dockerBinary, "tag", "emptyfs:latest", fmt.Sprintf("%v-one:latest", repoName))
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
t.Fatalf("failed to tag repo: %s, %v", out, err)
c.Fatalf("failed to tag repo: %s, %v", out, err)
}
defer deleteImages(repoName + "-one")
@@ -275,7 +271,7 @@ func TestSaveMultipleNames(t *testing.T) {
tagCmd = exec.Command(dockerBinary, "tag", "emptyfs:latest", fmt.Sprintf("%v-two:latest", repoName))
out, _, err := runCommandWithOutput(tagCmd)
if err != nil {
t.Fatalf("failed to tag repo: %s, %v", out, err)
c.Fatalf("failed to tag repo: %s, %v", out, err)
}
defer deleteImages(repoName + "-two")
@@ -285,13 +281,12 @@ func TestSaveMultipleNames(t *testing.T) {
exec.Command("grep", "-q", "-E", "(-one|-two)"),
)
if err != nil {
t.Fatalf("failed to save multiple repos: %s, %v", out, err)
c.Fatalf("failed to save multiple repos: %s, %v", out, err)
}
logDone("save - save by multiple names")
}
func TestSaveRepoWithMultipleImages(t *testing.T) {
func (s *DockerSuite) TestSaveRepoWithMultipleImages(c *check.C) {
makeImage := func(from string, tag string) string {
runCmd := exec.Command(dockerBinary, "run", "-d", from, "true")
@@ -300,14 +295,14 @@ func TestSaveRepoWithMultipleImages(t *testing.T) {
err error
)
if out, _, err = runCommandWithOutput(runCmd); err != nil {
t.Fatalf("failed to create a container: %v %v", out, err)
c.Fatalf("failed to create a container: %v %v", out, err)
}
cleanedContainerID := strings.TrimSpace(out)
defer deleteContainer(cleanedContainerID)
commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID, tag)
if out, _, err = runCommandWithOutput(commitCmd); err != nil {
t.Fatalf("failed to commit container: %v %v", out, err)
c.Fatalf("failed to commit container: %v %v", out, err)
}
imageID := strings.TrimSpace(out)
return imageID
@@ -331,14 +326,14 @@ func TestSaveRepoWithMultipleImages(t *testing.T) {
exec.Command("grep", "VERSION"),
exec.Command("cut", "-d", "/", "-f1"))
if err != nil {
t.Fatalf("failed to save multiple images: %s, %v", out, err)
c.Fatalf("failed to save multiple images: %s, %v", out, err)
}
actual := strings.Split(strings.TrimSpace(out), "\n")
// make the list of expected layers
out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "history", "-q", "--no-trunc", "busybox:latest"))
if err != nil {
t.Fatalf("failed to get history: %s, %v", out, err)
c.Fatalf("failed to get history: %s, %v", out, err)
}
expected := append(strings.Split(strings.TrimSpace(out), "\n"), idFoo, idBar)
@@ -346,21 +341,20 @@ func TestSaveRepoWithMultipleImages(t *testing.T) {
sort.Strings(actual)
sort.Strings(expected)
if !reflect.DeepEqual(expected, actual) {
t.Fatalf("achive does not contains the right layers: got %v, expected %v", actual, expected)
c.Fatalf("achive does not contains the right layers: got %v, expected %v", actual, expected)
}
logDone("save - save repository with multiple images")
}
// Issue #6722 #5892 ensure directories are included in changes
func TestSaveDirectoryPermissions(t *testing.T) {
func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) {
layerEntries := []string{"opt/", "opt/a/", "opt/a/b/", "opt/a/b/c"}
layerEntriesAUFS := []string{"./", ".wh..wh.aufs", ".wh..wh.orph/", ".wh..wh.plnk/", "opt/", "opt/a/", "opt/a/b/", "opt/a/b/c"}
name := "save-directory-permissions"
tmpDir, err := ioutil.TempDir("", "save-layers-with-directories")
if err != nil {
t.Errorf("failed to create temporary directory: %s", err)
c.Errorf("failed to create temporary directory: %s", err)
}
extractionDirectory := filepath.Join(tmpDir, "image-extraction-dir")
os.Mkdir(extractionDirectory, 0777)
@@ -373,19 +367,19 @@ func TestSaveDirectoryPermissions(t *testing.T) {
RUN touch /opt/a/b/c && chown user:user /opt/a/b/c`,
true)
if err != nil {
t.Fatal(err)
c.Fatal(err)
}
if out, _, err := runCommandPipelineWithOutput(
exec.Command(dockerBinary, "save", name),
exec.Command("tar", "-xf", "-", "-C", extractionDirectory),
); err != nil {
t.Errorf("failed to save and extract image: %s", out)
c.Errorf("failed to save and extract image: %s", out)
}
dirs, err := ioutil.ReadDir(extractionDirectory)
if err != nil {
t.Errorf("failed to get a listing of the layer directories: %s", err)
c.Errorf("failed to get a listing of the layer directories: %s", err)
}
found := false
@@ -396,7 +390,7 @@ func TestSaveDirectoryPermissions(t *testing.T) {
f, err := os.Open(layerPath)
if err != nil {
t.Fatalf("failed to open %s: %s", layerPath, err)
c.Fatalf("failed to open %s: %s", layerPath, err)
}
entries, err := ListTar(f)
@@ -406,7 +400,7 @@ func TestSaveDirectoryPermissions(t *testing.T) {
}
}
if err != nil {
t.Fatalf("encountered error while listing tar entries: %s", err)
c.Fatalf("encountered error while listing tar entries: %s", err)
}
if reflect.DeepEqual(entriesSansDev, layerEntries) || reflect.DeepEqual(entriesSansDev, layerEntriesAUFS) {
@@ -417,8 +411,7 @@ func TestSaveDirectoryPermissions(t *testing.T) {
}
if !found {
t.Fatalf("failed to find the layer with the right content listing")
c.Fatalf("failed to find the layer with the right content listing")
}
logDone("save - ensure directories exist in exported layers")
}