From 18c7e8b927928654a67ce5d6637e42932fc3e7df Mon Sep 17 00:00:00 2001 From: linuxmercedes Date: Thu, 3 Jan 2019 15:50:20 -0600 Subject: [PATCH] Test: dockerfiles with no instructions are detected Signed-off-by: Natasha Jarus --- integration/build/build_test.go | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/integration/build/build_test.go b/integration/build/build_test.go index fafba447f2..65856a9bb5 100644 --- a/integration/build/build_test.go +++ b/integration/build/build_test.go @@ -467,6 +467,61 @@ RUN for g in $(seq 0 8); do dd if=/dev/urandom of=rnd bs=1K count=1 seek=$((1024 assert.Check(t, is.Contains(out.String(), "Successfully built")) } +func TestBuildWithEmptyDockerfile(t *testing.T) { + ctx := context.TODO() + defer setupTest(t)() + + tests := []struct { + name string + dockerfile string + expectedErr string + }{ + { + name: "empty-dockerfile", + dockerfile: "", + expectedErr: "cannot be empty", + }, + { + name: "empty-lines-dockerfile", + dockerfile: ` + + + + `, + expectedErr: "file with no instructions", + }, + { + name: "comment-only-dockerfile", + dockerfile: `# this is a comment`, + expectedErr: "file with no instructions", + }, + } + + apiclient := testEnv.APIClient() + + for _, tc := range tests { + tc := tc + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + + buf := bytes.NewBuffer(nil) + w := tar.NewWriter(buf) + writeTarRecord(t, w, "Dockerfile", tc.dockerfile) + err := w.Close() + assert.NilError(t, err) + + _, err = apiclient.ImageBuild(ctx, + buf, + types.ImageBuildOptions{ + Remove: true, + ForceRemove: true, + }) + + assert.Check(t, is.Contains(err.Error(), tc.expectedErr)) + }) + } +} + func writeTarRecord(t *testing.T, w *tar.Writer, fn, contents string) { err := w.WriteHeader(&tar.Header{ Name: fn,