Browse code

Test: dockerfiles with no instructions are detected

Signed-off-by: Natasha Jarus <linuxmercedes@gmail.com>

linuxmercedes authored on 2019/01/04 06:50:20
Showing 1 changed files
... ...
@@ -467,6 +467,61 @@ RUN for g in $(seq 0 8); do dd if=/dev/urandom of=rnd bs=1K count=1 seek=$((1024
467 467
 	assert.Check(t, is.Contains(out.String(), "Successfully built"))
468 468
 }
469 469
 
470
+func TestBuildWithEmptyDockerfile(t *testing.T) {
471
+	ctx := context.TODO()
472
+	defer setupTest(t)()
473
+
474
+	tests := []struct {
475
+		name        string
476
+		dockerfile  string
477
+		expectedErr string
478
+	}{
479
+		{
480
+			name:        "empty-dockerfile",
481
+			dockerfile:  "",
482
+			expectedErr: "cannot be empty",
483
+		},
484
+		{
485
+			name: "empty-lines-dockerfile",
486
+			dockerfile: `
487
+			
488
+			
489
+			
490
+			`,
491
+			expectedErr: "file with no instructions",
492
+		},
493
+		{
494
+			name:        "comment-only-dockerfile",
495
+			dockerfile:  `# this is a comment`,
496
+			expectedErr: "file with no instructions",
497
+		},
498
+	}
499
+
500
+	apiclient := testEnv.APIClient()
501
+
502
+	for _, tc := range tests {
503
+		tc := tc
504
+		t.Run(tc.name, func(t *testing.T) {
505
+			t.Parallel()
506
+
507
+			buf := bytes.NewBuffer(nil)
508
+			w := tar.NewWriter(buf)
509
+			writeTarRecord(t, w, "Dockerfile", tc.dockerfile)
510
+			err := w.Close()
511
+			assert.NilError(t, err)
512
+
513
+			_, err = apiclient.ImageBuild(ctx,
514
+				buf,
515
+				types.ImageBuildOptions{
516
+					Remove:      true,
517
+					ForceRemove: true,
518
+				})
519
+
520
+			assert.Check(t, is.Contains(err.Error(), tc.expectedErr))
521
+		})
522
+	}
523
+}
524
+
470 525
 func writeTarRecord(t *testing.T, w *tar.Writer, fn, contents string) {
471 526
 	err := w.WriteHeader(&tar.Header{
472 527
 		Name:     fn,