diff --git a/integration-cli/build_tests/TestBuildCacheADD/1/Dockerfile b/integration-cli/build_tests/TestBuildCacheADD/1/Dockerfile deleted file mode 100644 index 7287771992..0000000000 --- a/integration-cli/build_tests/TestBuildCacheADD/1/Dockerfile +++ /dev/null @@ -1,2 +0,0 @@ -FROM busybox -ADD https://index.docker.io/robots.txt / diff --git a/integration-cli/build_tests/TestBuildCacheADD/2/Dockerfile b/integration-cli/build_tests/TestBuildCacheADD/2/Dockerfile deleted file mode 100644 index afe79b84b6..0000000000 --- a/integration-cli/build_tests/TestBuildCacheADD/2/Dockerfile +++ /dev/null @@ -1,2 +0,0 @@ -FROM busybox -ADD http://example.com/index.html / diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index c9e0a48e65..bcff199c85 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -15,38 +15,34 @@ import ( ) func TestBuildCacheADD(t *testing.T) { - var ( - exitCode int - out string - err error - ) - { - buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildCacheADD", "1") - out, exitCode, err = dockerCmdInDir(t, buildDirectory, "build", "-t", "testcacheadd1", ".") - 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") - } + name := "testbuildtwoimageswithadd" + defer deleteImages(name) + server, err := fakeStorage(map[string]string{ + "robots.txt": "hello", + "index.html": "world", + }) + if err != nil { + t.Fatal(err) } - { - buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildCacheADD", "2") - out, exitCode, err = dockerCmdInDir(t, buildDirectory, "build", "-t", "testcacheadd2", ".") - 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") - } + defer server.Close() + if _, err := buildImage(name, + fmt.Sprintf(`FROM scratch + ADD %s/robots.txt /`, server.URL), + true); err != nil { + t.Fatal(err) + } + out, _, err := buildImageWithOut(name, + fmt.Sprintf(`FROM scratch + ADD %s/index.html /`, server.URL), + true) + if err != nil { + t.Fatal(err) } - if strings.Contains(out, "Using cache") { t.Fatal("2nd build used cache on ADD, it shouldn't") } - deleteImages("testcacheadd1") - deleteImages("testcacheadd2") - - logDone("build - build two images with ADD") + logDone("build - build two images with remote ADD") } func TestBuildSixtySteps(t *testing.T) { diff --git a/integration-cli/docker_utils.go b/integration-cli/docker_utils.go index f4f19403bb..5561fc24dc 100644 --- a/integration-cli/docker_utils.go +++ b/integration-cli/docker_utils.go @@ -240,7 +240,7 @@ func getIDByName(name string) (string, error) { return inspectField(name, "Id") } -func buildImage(name, dockerfile string, useCache bool) (string, error) { +func buildImageWithOut(name, dockerfile string, useCache bool) (string, string, error) { args := []string{"build", "-t", name} if !useCache { args = append(args, "--no-cache") @@ -250,9 +250,18 @@ func buildImage(name, dockerfile string, useCache bool) (string, error) { buildCmd.Stdin = strings.NewReader(dockerfile) out, exitCode, err := runCommandWithOutput(buildCmd) if err != nil || exitCode != 0 { - return "", fmt.Errorf("failed to build the image: %s", out) + return "", out, fmt.Errorf("failed to build the image: %s", out) } - return getIDByName(name) + id, err := getIDByName(name) + if err != nil { + return "", out, err + } + return id, out, nil +} + +func buildImage(name, dockerfile string, useCache bool) (string, error) { + id, _, err := buildImageWithOut(name, dockerfile, useCache) + return id, err } func buildImageFromContext(name string, ctx *FakeContext, useCache bool) (string, error) {