From 49fa1af9ed7893528de1a88c741d4ec6f5cac060 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Fri, 8 Feb 2019 10:35:05 +0100 Subject: [PATCH] Adding a few tests for `skaffold build` See #441 Signed-off-by: David Gageot --- integration/run_test.go | 14 ++++++-- integration/testdata/build/Dockerfile | 3 ++ .../testdata/build/multi-env/Dockerfile | 7 ++++ integration/testdata/build/multi-env/file1 | 1 + integration/testdata/build/multi-env/file2 | 1 + integration/testdata/build/skaffold.yaml | 35 +++++++++++++++++++ .../testdata/build/sub-directory/Dockerfile | 4 +++ .../testdata/build/sub-directory/file1 | 1 + .../testdata/build/sub-directory/file2 | 1 + integration/testdata/build/targets/Dockerfile | 9 +++++ integration/testdata/build/targets/file1 | 1 + integration/testdata/build/targets/file2 | 1 + integration/testdata/build/targets/file3 | 1 + 13 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 integration/testdata/build/Dockerfile create mode 100644 integration/testdata/build/multi-env/Dockerfile create mode 100644 integration/testdata/build/multi-env/file1 create mode 100644 integration/testdata/build/multi-env/file2 create mode 100644 integration/testdata/build/skaffold.yaml create mode 100644 integration/testdata/build/sub-directory/Dockerfile create mode 100644 integration/testdata/build/sub-directory/file1 create mode 100644 integration/testdata/build/sub-directory/file2 create mode 100644 integration/testdata/build/targets/Dockerfile create mode 100644 integration/testdata/build/targets/file1 create mode 100644 integration/testdata/build/targets/file2 create mode 100644 integration/testdata/build/targets/file3 diff --git a/integration/run_test.go b/integration/run_test.go index d6d20c82945..d79ad94ef54 100644 --- a/integration/run_test.go +++ b/integration/run_test.go @@ -313,12 +313,22 @@ func TestFix(t *testing.T) { runCmd := exec.Command("skaffold", "run", "--namespace", ns.Name, "-f", "-") runCmd.Dir = "testdata/fix" runCmd.Stdin = bytes.NewReader(out) - err = util.RunCmd(runCmd) - if err != nil { + + if err := util.RunCmd(runCmd); err != nil { t.Fatalf("testing error: %v", err) } } +func TestBuild(t *testing.T) { + buildCmd := exec.Command("skaffold", "build") + buildCmd.Dir = "testdata/build" + + out, err := util.RunCmdOut(buildCmd) + if err != nil { + t.Fatalf("testing error: %v, %s", err, out) + } +} + func TestListConfig(t *testing.T) { baseConfig := &config.Config{ Global: &config.ContextConfig{ diff --git a/integration/testdata/build/Dockerfile b/integration/testdata/build/Dockerfile new file mode 100644 index 00000000000..4652feec056 --- /dev/null +++ b/integration/testdata/build/Dockerfile @@ -0,0 +1,3 @@ +FROM busybox + +COPY . /data diff --git a/integration/testdata/build/multi-env/Dockerfile b/integration/testdata/build/multi-env/Dockerfile new file mode 100644 index 00000000000..cfa889d4a9c --- /dev/null +++ b/integration/testdata/build/multi-env/Dockerfile @@ -0,0 +1,7 @@ +FROM busybox + +ENV file1=file1 \ + file2=file2 + +COPY $file1 $file2 /data/ +RUN [ "$(find /data -type f | wc -l | xargs)" == "2" ] \ No newline at end of file diff --git a/integration/testdata/build/multi-env/file1 b/integration/testdata/build/multi-env/file1 new file mode 100644 index 00000000000..08219db9b09 --- /dev/null +++ b/integration/testdata/build/multi-env/file1 @@ -0,0 +1 @@ +file1 \ No newline at end of file diff --git a/integration/testdata/build/multi-env/file2 b/integration/testdata/build/multi-env/file2 new file mode 100644 index 00000000000..30d67d4672d --- /dev/null +++ b/integration/testdata/build/multi-env/file2 @@ -0,0 +1 @@ +file2 \ No newline at end of file diff --git a/integration/testdata/build/skaffold.yaml b/integration/testdata/build/skaffold.yaml new file mode 100644 index 00000000000..e4d7473807d --- /dev/null +++ b/integration/testdata/build/skaffold.yaml @@ -0,0 +1,35 @@ +apiVersion: skaffold/v1beta5 +kind: Config +build: + local: + push: false + artifacts: + # A simple Docker build + - image: simple-build + + # Building from a sub-directory + - image: sub-directory + context: sub-directory + + # Testing multiline env variables in Dockerfiles + # Would have caught #1624 + - image: multi-env + context: multi-env + + # Testing Dockerfiles with targets + - image: targets + context: targets + + # Providing a target + # Would have caught #1605 + - image: target1 + context: targets + docker: + target: target1 + + # Providing another target + # Would have caught #1605 + - image: target2 + context: targets + docker: + target: target2 diff --git a/integration/testdata/build/sub-directory/Dockerfile b/integration/testdata/build/sub-directory/Dockerfile new file mode 100644 index 00000000000..3830aaed78e --- /dev/null +++ b/integration/testdata/build/sub-directory/Dockerfile @@ -0,0 +1,4 @@ +FROM busybox + +COPY file1 file2 /data/ +RUN [ "$(find /data -type f | wc -l | xargs)" == "2" ] \ No newline at end of file diff --git a/integration/testdata/build/sub-directory/file1 b/integration/testdata/build/sub-directory/file1 new file mode 100644 index 00000000000..08219db9b09 --- /dev/null +++ b/integration/testdata/build/sub-directory/file1 @@ -0,0 +1 @@ +file1 \ No newline at end of file diff --git a/integration/testdata/build/sub-directory/file2 b/integration/testdata/build/sub-directory/file2 new file mode 100644 index 00000000000..30d67d4672d --- /dev/null +++ b/integration/testdata/build/sub-directory/file2 @@ -0,0 +1 @@ +file2 \ No newline at end of file diff --git a/integration/testdata/build/targets/Dockerfile b/integration/testdata/build/targets/Dockerfile new file mode 100644 index 00000000000..9440d8c8673 --- /dev/null +++ b/integration/testdata/build/targets/Dockerfile @@ -0,0 +1,9 @@ +FROM busybox as target1 + +COPY file1 file2 /data/ +RUN [ "$(find /data -type f | wc -l | xargs)" == "2" ] + +FROM busybox as target2 + +COPY file3 /data/ +RUN [ "$(find /data -type f | wc -l | xargs)" == "1" ] \ No newline at end of file diff --git a/integration/testdata/build/targets/file1 b/integration/testdata/build/targets/file1 new file mode 100644 index 00000000000..08219db9b09 --- /dev/null +++ b/integration/testdata/build/targets/file1 @@ -0,0 +1 @@ +file1 \ No newline at end of file diff --git a/integration/testdata/build/targets/file2 b/integration/testdata/build/targets/file2 new file mode 100644 index 00000000000..30d67d4672d --- /dev/null +++ b/integration/testdata/build/targets/file2 @@ -0,0 +1 @@ +file2 \ No newline at end of file diff --git a/integration/testdata/build/targets/file3 b/integration/testdata/build/targets/file3 new file mode 100644 index 00000000000..873fb8d667d --- /dev/null +++ b/integration/testdata/build/targets/file3 @@ -0,0 +1 @@ +file3 \ No newline at end of file