Browse code

Rewrite TestAddSingleFileToNonExistDir to not use fixtures

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

Alexandr Morozov authored on 2014/09/23 00:41:13
Showing 3 changed files
1 1
deleted file mode 100644
... ...
@@ -1,9 +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_file /test_dir/
7
-RUN [ $(ls -l / | grep test_dir | awk '{print $3":"$4}') = 'root:root' ]
8
-RUN [ $(ls -l /test_dir/test_file | awk '{print $3":"$4}') = 'root:root' ]
9
-RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]
10 1
deleted file mode 100644
... ...
@@ -198,17 +198,26 @@ func TestBuildCopyMultipleFilesToFile(t *testing.T) {
198 198
 }
199 199
 
200 200
 func TestBuildAddSingleFileToNonExistDir(t *testing.T) {
201
-	buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestAdd")
202
-	out, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testaddimg", "SingleFileToNonExistDir")
203
-	errorOut(err, t, fmt.Sprintf("build failed to complete: %v %v", out, err))
204
-
205
-	if err != nil || exitCode != 0 {
206
-		t.Fatal("failed to build the image")
201
+	name := "testaddsinglefiletononexistdir"
202
+	defer deleteImages(name)
203
+	ctx, err := fakeContext(`FROM busybox
204
+RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
205
+RUN echo 'dockerio:x:1001:' >> /etc/group
206
+RUN touch /exists
207
+RUN chown dockerio.dockerio /exists
208
+ADD test_file /test_dir/
209
+RUN [ $(ls -l / | grep test_dir | awk '{print $3":"$4}') = 'root:root' ]
210
+RUN [ $(ls -l /test_dir/test_file | awk '{print $3":"$4}') = 'root:root' ]
211
+RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`,
212
+		map[string]string{
213
+			"test_file": "test1",
214
+		})
215
+	if err != nil {
216
+		t.Fatal(err)
217
+	}
218
+	if _, err := buildImageFromContext(name, ctx, true); err != nil {
219
+		t.Fatal(err)
207 220
 	}
208
-
209
-	deleteImages("testaddimg")
210
-
211
-	logDone("build - add single file to non-existing dir")
212 221
 }
213 222
 
214 223
 func TestBuildAddDirContentToRoot(t *testing.T) {