|
@@ -834,6 +834,126 @@ func TestBuildCopyMultipleFilesToFile(t *testing.T) {
|
|
|
logDone("build - multiple copy files to file")
|
|
|
}
|
|
|
|
|
|
+func TestBuildAddFileWithWhitespace(t *testing.T) {
|
|
|
+ name := "testaddfilewithwhitespace"
|
|
|
+ defer deleteImages(name)
|
|
|
+ ctx, err := fakeContext(`FROM busybox
|
|
|
+RUN mkdir "/test dir"
|
|
|
+RUN mkdir "/test_dir"
|
|
|
+ADD [ "test file1", "/test_file1" ]
|
|
|
+ADD [ "test_file2", "/test file2" ]
|
|
|
+ADD [ "test file3", "/test file3" ]
|
|
|
+ADD [ "test dir/test_file4", "/test_dir/test_file4" ]
|
|
|
+ADD [ "test_dir/test_file5", "/test dir/test_file5" ]
|
|
|
+ADD [ "test dir/test_file6", "/test dir/test_file6" ]
|
|
|
+RUN [ $(cat "/test_file1") = 'test1' ]
|
|
|
+RUN [ $(cat "/test file2") = 'test2' ]
|
|
|
+RUN [ $(cat "/test file3") = 'test3' ]
|
|
|
+RUN [ $(cat "/test_dir/test_file4") = 'test4' ]
|
|
|
+RUN [ $(cat "/test dir/test_file5") = 'test5' ]
|
|
|
+RUN [ $(cat "/test dir/test_file6") = 'test6' ]`,
|
|
|
+ map[string]string{
|
|
|
+ "test file1": "test1",
|
|
|
+ "test_file2": "test2",
|
|
|
+ "test file3": "test3",
|
|
|
+ "test dir/test_file4": "test4",
|
|
|
+ "test_dir/test_file5": "test5",
|
|
|
+ "test dir/test_file6": "test6",
|
|
|
+ })
|
|
|
+ defer ctx.Close()
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if _, err := buildImageFromContext(name, ctx, true); err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+ logDone("build - add file with whitespace")
|
|
|
+}
|
|
|
+
|
|
|
+func TestBuildCopyFileWithWhitespace(t *testing.T) {
|
|
|
+ name := "testcopyfilewithwhitespace"
|
|
|
+ defer deleteImages(name)
|
|
|
+ ctx, err := fakeContext(`FROM busybox
|
|
|
+RUN mkdir "/test dir"
|
|
|
+RUN mkdir "/test_dir"
|
|
|
+COPY [ "test file1", "/test_file1" ]
|
|
|
+COPY [ "test_file2", "/test file2" ]
|
|
|
+COPY [ "test file3", "/test file3" ]
|
|
|
+COPY [ "test dir/test_file4", "/test_dir/test_file4" ]
|
|
|
+COPY [ "test_dir/test_file5", "/test dir/test_file5" ]
|
|
|
+COPY [ "test dir/test_file6", "/test dir/test_file6" ]
|
|
|
+RUN [ $(cat "/test_file1") = 'test1' ]
|
|
|
+RUN [ $(cat "/test file2") = 'test2' ]
|
|
|
+RUN [ $(cat "/test file3") = 'test3' ]
|
|
|
+RUN [ $(cat "/test_dir/test_file4") = 'test4' ]
|
|
|
+RUN [ $(cat "/test dir/test_file5") = 'test5' ]
|
|
|
+RUN [ $(cat "/test dir/test_file6") = 'test6' ]`,
|
|
|
+ map[string]string{
|
|
|
+ "test file1": "test1",
|
|
|
+ "test_file2": "test2",
|
|
|
+ "test file3": "test3",
|
|
|
+ "test dir/test_file4": "test4",
|
|
|
+ "test_dir/test_file5": "test5",
|
|
|
+ "test dir/test_file6": "test6",
|
|
|
+ })
|
|
|
+ defer ctx.Close()
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if _, err := buildImageFromContext(name, ctx, true); err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+ logDone("build - copy file with whitespace")
|
|
|
+}
|
|
|
+
|
|
|
+func TestBuildAddMultipleFilesToFileWithWhitespace(t *testing.T) {
|
|
|
+ name := "testaddmultiplefilestofilewithwhitespace"
|
|
|
+ defer deleteImages(name)
|
|
|
+ ctx, err := fakeContext(`FROM busybox
|
|
|
+ ADD [ "test file1", "test file2", "test" ]
|
|
|
+ `,
|
|
|
+ map[string]string{
|
|
|
+ "test file1": "test1",
|
|
|
+ "test file2": "test2",
|
|
|
+ })
|
|
|
+ defer ctx.Close()
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ expected := "When using ADD with more than one source file, the destination must be a directory and end with a /"
|
|
|
+ if _, err := buildImageFromContext(name, ctx, true); err == nil || !strings.Contains(err.Error(), expected) {
|
|
|
+ t.Fatalf("Wrong error: (should contain \"%s\") got:\n%v", expected, err)
|
|
|
+ }
|
|
|
+
|
|
|
+ logDone("build - multiple add files to file with whitespace")
|
|
|
+}
|
|
|
+
|
|
|
+func TestBuildCopyMultipleFilesToFileWithWhitespace(t *testing.T) {
|
|
|
+ name := "testcopymultiplefilestofilewithwhitespace"
|
|
|
+ defer deleteImages(name)
|
|
|
+ ctx, err := fakeContext(`FROM busybox
|
|
|
+ COPY [ "test file1", "test file2", "test" ]
|
|
|
+ `,
|
|
|
+ map[string]string{
|
|
|
+ "test file1": "test1",
|
|
|
+ "test file2": "test2",
|
|
|
+ })
|
|
|
+ defer ctx.Close()
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ expected := "When using COPY with more than one source file, the destination must be a directory and end with a /"
|
|
|
+ if _, err := buildImageFromContext(name, ctx, true); err == nil || !strings.Contains(err.Error(), expected) {
|
|
|
+ t.Fatalf("Wrong error: (should contain \"%s\") got:\n%v", expected, err)
|
|
|
+ }
|
|
|
+
|
|
|
+ logDone("build - multiple copy files to file with whitespace")
|
|
|
+}
|
|
|
+
|
|
|
func TestBuildCopyWildcard(t *testing.T) {
|
|
|
name := "testcopywildcard"
|
|
|
defer deleteImages(name)
|