Browse code

Add test to enforce volume build content

This tests ensures that the content from a dir within a build is carried
over even if VOLUME for that dir is specified in the Dockerfile. This
test ensures this long standing functionality.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>

Michael Crosby authored on 2014/12/13 04:15:31
Showing 1 changed files
... ...
@@ -3914,3 +3914,37 @@ RUN [ ! -e /injected ]`,
3914 3914
 
3915 3915
 	logDone("build - xz host is being used")
3916 3916
 }
3917
+
3918
+func TestBuildVolumesRetainContents(t *testing.T) {
3919
+	var (
3920
+		name     = "testbuildvolumescontent"
3921
+		expected = "some text"
3922
+	)
3923
+	defer deleteImages(name)
3924
+	ctx, err := fakeContext(`
3925
+FROM busybox
3926
+COPY content /foo/file
3927
+VOLUME /foo
3928
+CMD cat /foo/file`,
3929
+		map[string]string{
3930
+			"content": expected,
3931
+		})
3932
+	if err != nil {
3933
+		t.Fatal(err)
3934
+	}
3935
+	defer ctx.Close()
3936
+
3937
+	if _, err := buildImageFromContext(name, ctx, false); err != nil {
3938
+		t.Fatal(err)
3939
+	}
3940
+
3941
+	out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--rm", name))
3942
+	if err != nil {
3943
+		t.Fatal(err)
3944
+	}
3945
+	if out != expected {
3946
+		t.Fatalf("expected file contents for /foo/file to be %q but received %q", expected, out)
3947
+	}
3948
+
3949
+	logDone("build - volumes retain contents in build")
3950
+}