浏览代码

Move volume build test to integration-cli

Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)
LK4D4 11 年之前
父节点
当前提交
11f7f0bf9b
共有 2 个文件被更改,包括 33 次插入20 次删除
  1. 33 0
      integration-cli/docker_cli_build_test.go
  2. 0 20
      integration/buildfile_test.go

+ 33 - 0
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

+ 0 - 20
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}