Browse code

Remove internet dependency from TestBuildCacheADD

Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com>

Alexandr Morozov authored on 2014/08/18 19:13:43
Showing 4 changed files
1 1
deleted file mode 100644
... ...
@@ -1,2 +0,0 @@
1
-FROM busybox
2
-ADD https://index.docker.io/robots.txt /
3 1
deleted file mode 100644
... ...
@@ -1,2 +0,0 @@
1
-FROM busybox
2
-ADD http://example.com/index.html /
... ...
@@ -15,38 +15,34 @@ import (
15 15
 )
16 16
 
17 17
 func TestBuildCacheADD(t *testing.T) {
18
-	var (
19
-		exitCode int
20
-		out      string
21
-		err      error
22
-	)
23
-	{
24
-		buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildCacheADD", "1")
25
-		out, exitCode, err = dockerCmdInDir(t, buildDirectory, "build", "-t", "testcacheadd1", ".")
26
-		errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
27
-
28
-		if err != nil || exitCode != 0 {
29
-			t.Fatal("failed to build the image")
30
-		}
18
+	name := "testbuildtwoimageswithadd"
19
+	defer deleteImages(name)
20
+	server, err := fakeStorage(map[string]string{
21
+		"robots.txt": "hello",
22
+		"index.html": "world",
23
+	})
24
+	if err != nil {
25
+		t.Fatal(err)
31 26
 	}
32
-	{
33
-		buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildCacheADD", "2")
34
-		out, exitCode, err = dockerCmdInDir(t, buildDirectory, "build", "-t", "testcacheadd2", ".")
35
-		errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
36
-
37
-		if err != nil || exitCode != 0 {
38
-			t.Fatal("failed to build the image")
39
-		}
27
+	defer server.Close()
28
+	if _, err := buildImage(name,
29
+		fmt.Sprintf(`FROM scratch
30
+		ADD %s/robots.txt /`, server.URL),
31
+		true); err != nil {
32
+		t.Fatal(err)
33
+	}
34
+	out, _, err := buildImageWithOut(name,
35
+		fmt.Sprintf(`FROM scratch
36
+		ADD %s/index.html /`, server.URL),
37
+		true)
38
+	if err != nil {
39
+		t.Fatal(err)
40 40
 	}
41
-
42 41
 	if strings.Contains(out, "Using cache") {
43 42
 		t.Fatal("2nd build used cache on ADD, it shouldn't")
44 43
 	}
45 44
 
46
-	deleteImages("testcacheadd1")
47
-	deleteImages("testcacheadd2")
48
-
49
-	logDone("build - build two images with ADD")
45
+	logDone("build - build two images with remote ADD")
50 46
 }
51 47
 
52 48
 func TestBuildSixtySteps(t *testing.T) {
... ...
@@ -240,7 +240,7 @@ func getIDByName(name string) (string, error) {
240 240
 	return inspectField(name, "Id")
241 241
 }
242 242
 
243
-func buildImage(name, dockerfile string, useCache bool) (string, error) {
243
+func buildImageWithOut(name, dockerfile string, useCache bool) (string, string, error) {
244 244
 	args := []string{"build", "-t", name}
245 245
 	if !useCache {
246 246
 		args = append(args, "--no-cache")
... ...
@@ -250,9 +250,18 @@ func buildImage(name, dockerfile string, useCache bool) (string, error) {
250 250
 	buildCmd.Stdin = strings.NewReader(dockerfile)
251 251
 	out, exitCode, err := runCommandWithOutput(buildCmd)
252 252
 	if err != nil || exitCode != 0 {
253
-		return "", fmt.Errorf("failed to build the image: %s", out)
253
+		return "", out, fmt.Errorf("failed to build the image: %s", out)
254 254
 	}
255
-	return getIDByName(name)
255
+	id, err := getIDByName(name)
256
+	if err != nil {
257
+		return "", out, err
258
+	}
259
+	return id, out, nil
260
+}
261
+
262
+func buildImage(name, dockerfile string, useCache bool) (string, error) {
263
+	id, _, err := buildImageWithOut(name, dockerfile, useCache)
264
+	return id, err
256 265
 }
257 266
 
258 267
 func buildImageFromContext(name string, ctx *FakeContext, useCache bool) (string, error) {