From 11f7f0bf9b510e09a853a9fd2030a95b72462164 Mon Sep 17 00:00:00 2001 From: LK4D4 Date: Thu, 22 May 2014 23:16:27 +0400 Subject: [PATCH] Move volume build test to integration-cli Docker-DCO-1.1-Signed-off-by: Alexandr Morozov (github: LK4D4) --- integration-cli/docker_cli_build_test.go | 33 ++++++++++++++++++++++++ integration/buildfile_test.go | 20 -------------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 4bbe4c6dc3..931a61b57d 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -10,6 +10,25 @@ import ( "time" ) +func checkSimpleBuild(t *testing.T, dockerfile, name, inspectFormat, expected string) { + buildCmd := exec.Command(dockerBinary, "build", "-t", name, "-") + buildCmd.Stdin = strings.NewReader(dockerfile) + out, exitCode, err := runCommandWithOutput(buildCmd) + errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err)) + if err != nil || exitCode != 0 { + t.Fatal("failed to build the image") + } + inspectCmd := exec.Command(dockerBinary, "inspect", "-f", inspectFormat, name) + out, exitCode, err = runCommandWithOutput(inspectCmd) + if err != nil || exitCode != 0 { + t.Fatalf("failed to inspect the image: %s", out) + } + out = strings.TrimSpace(out) + if out != expected { + t.Fatalf("From format %s expected %s, got %s", inspectFormat, expected, out) + } +} + func TestBuildCacheADD(t *testing.T) { buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildCacheADD", "1") buildCmd := exec.Command(dockerBinary, "build", "-t", "testcacheadd1", ".") @@ -413,6 +432,20 @@ func TestBuildRm(t *testing.T) { logDone("build - ensure --rm=false overrides the default") } +func TestBuildWithVolume(t *testing.T) { + checkSimpleBuild(t, + ` + FROM scratch + VOLUME /test + `, + "testbuildimg", + "{{json .config.Volumes}}", + `{"/test":{}}`) + + deleteImages("testbuildimg") + logDone("build - with volume") +} + // TODO: TestCaching // TODO: TestADDCacheInvalidation diff --git a/integration/buildfile_test.go b/integration/buildfile_test.go index e113cdf512..c326e94cff 100644 --- a/integration/buildfile_test.go +++ b/integration/buildfile_test.go @@ -414,26 +414,6 @@ func buildImage(context testContextTemplate, t *testing.T, eng *engine.Engine, u return image, err } -func TestVolume(t *testing.T) { - img, err := buildImage(testContextTemplate{` - from {IMAGE} - volume /test - cmd Hello world - `, nil, nil}, t, nil, true) - if err != nil { - t.Fatal(err) - } - - if len(img.Config.Volumes) == 0 { - t.Fail() - } - for key := range img.Config.Volumes { - if key != "/test" { - t.Fail() - } - } -} - func TestBuildMaintainer(t *testing.T) { img, err := buildImage(testContextTemplate{` from {IMAGE}