Browse code

Rewrite TestBuildAddWholeDirToRoot to not use fixtures

Signed-off-by: Alexandr Morozov <lk4d4@docker.com>

Alexandr Morozov authored on 2014/09/23 02:36:43
Showing 2 changed files
1 1
deleted file mode 100644
... ...
@@ -1,11 +0,0 @@
1
-FROM busybox
2
-RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
3
-RUN echo 'dockerio:x:1001:' >> /etc/group
4
-RUN touch /exists
5
-RUN chown dockerio.dockerio exists
6
-ADD test_dir /test_dir
7
-RUN [ $(ls -l / | grep test_dir | awk '{print $3":"$4}') = 'root:root' ]
8
-RUN [ $(ls -l / | grep test_dir | awk '{print $1}') = 'drwxr-xr-x' ]
9
-RUN [ $(ls -l /test_dir/test_file | awk '{print $3":"$4}') = 'root:root' ]
10
-RUN [ $(ls -l /test_dir/test_file | awk '{print $1}') = '-rw-r--r--' ]
11
-RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]
... ...
@@ -269,35 +269,28 @@ RUN [ $(ls -l /exists/test_file | awk '{print $3":"$4}') = 'root:root' ]`,
269 269
 }
270 270
 
271 271
 func TestBuildAddWholeDirToRoot(t *testing.T) {
272
-	testDirName := "WholeDirToRoot"
273
-	sourceDirectory := filepath.Join(workingDirectory, "build_tests", "TestAdd", testDirName)
274
-	buildDirectory, err := ioutil.TempDir("", "test-build-add")
275
-	defer os.RemoveAll(buildDirectory)
276
-
277
-	err = copyWithCP(sourceDirectory, buildDirectory)
272
+	name := "testaddwholedirtoroot"
273
+	defer deleteImages(name)
274
+	ctx, err := fakeContext(`FROM busybox
275
+RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
276
+RUN echo 'dockerio:x:1001:' >> /etc/group
277
+RUN touch /exists
278
+RUN chown dockerio.dockerio exists
279
+ADD test_dir /test_dir
280
+RUN [ $(ls -l / | grep test_dir | awk '{print $3":"$4}') = 'root:root' ]
281
+RUN [ $(ls -l / | grep test_dir | awk '{print $1}') = 'drwxr-xr-x' ]
282
+RUN [ $(ls -l /test_dir/test_file | awk '{print $3":"$4}') = 'root:root' ]
283
+RUN [ $(ls -l /test_dir/test_file | awk '{print $1}') = '-rw-r--r--' ]
284
+RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`,
285
+		map[string]string{
286
+			"test_dir/test_file": "test1",
287
+		})
278 288
 	if err != nil {
279
-		t.Fatalf("failed to copy files to temporary directory: %s", err)
280
-	}
281
-
282
-	buildDirectory = filepath.Join(buildDirectory, testDirName)
283
-	test_dir := filepath.Join(buildDirectory, "test_dir")
284
-	if err := os.MkdirAll(test_dir, 0755); err != nil {
285 289
 		t.Fatal(err)
286 290
 	}
287
-	f, err := os.OpenFile(filepath.Join(test_dir, "test_file"), os.O_CREATE, 0644)
288
-	if err != nil {
291
+	if _, err := buildImageFromContext(name, ctx, true); err != nil {
289 292
 		t.Fatal(err)
290 293
 	}
291
-	f.Close()
292
-	out, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testaddimg", ".")
293
-	errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
294
-
295
-	if err != nil || exitCode != 0 {
296
-		t.Fatal("failed to build the image")
297
-	}
298
-
299
-	deleteImages("testaddimg")
300
-
301 294
 	logDone("build - add whole directory to root")
302 295
 }
303 296