From 76d5d3e2e240d27118cf49b93cd63a295a903872 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Fri, 9 Mar 2018 13:47:33 -0800 Subject: [PATCH] Added structure tests to integration test to test ENV command --- .../dockerfiles/Dockerfile_test_env | 5 ++ integration_tests/dockerfiles/test_env.yaml | 11 ++++ integration_tests/integration_test_yaml.go | 51 +++++++++++++++++-- 3 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 integration_tests/dockerfiles/Dockerfile_test_env create mode 100644 integration_tests/dockerfiles/test_env.yaml diff --git a/integration_tests/dockerfiles/Dockerfile_test_env b/integration_tests/dockerfiles/Dockerfile_test_env new file mode 100644 index 000000000..f88a560fe --- /dev/null +++ b/integration_tests/dockerfiles/Dockerfile_test_env @@ -0,0 +1,5 @@ +FROM gcr.io/distroless/base +ENV hey hey +ENV PATH /usr/local +ENV hey hello +ENV first=foo second=foo2 diff --git a/integration_tests/dockerfiles/test_env.yaml b/integration_tests/dockerfiles/test_env.yaml new file mode 100644 index 000000000..7c4847f52 --- /dev/null +++ b/integration_tests/dockerfiles/test_env.yaml @@ -0,0 +1,11 @@ +schemaVersion: '2.0.0' +metadataTest: + env: + - key: hey + value: hello + - key: PATH + value: /usr/local + - key: first + value: foo + - key: second + value: foo2 diff --git a/integration_tests/integration_test_yaml.go b/integration_tests/integration_test_yaml.go index d13be52e9..001461eb4 100644 --- a/integration_tests/integration_test_yaml.go +++ b/integration_tests/integration_test_yaml.go @@ -21,7 +21,7 @@ import ( "gopkg.in/yaml.v2" ) -var tests = []struct { +var fileTests = []struct { description string dockerfilePath string configPath string @@ -51,6 +51,20 @@ var tests = []struct { }, } +var structureTests = []struct { + description string + dockerfilePath string + structureTestYamlPath string + repo string +}{ + { + description: "test env", + dockerfilePath: "/workspace/integration_tests/dockerfiles/Dockerfile_test_env", + repo: "test-env", + structureTestYamlPath: "/workspace/integration_tests/dockerfiles/test_env.yaml", + }, +} + type step struct { Name string Args []string @@ -82,15 +96,23 @@ func main() { Name: ubuntuImage, Args: []string{"chmod", "+x", "container-diff-linux-amd64"}, } + structureTestsStep := step{ + Name: "gcr.io/cloud-builders/gsutil", + Args: []string{"cp", "gs://container-structure-test/latest/container-structure-test", "."}, + } + structureTestPermissions := step{ + Name: ubuntuImage, + Args: []string{"chmod", "+x", "container-structure-test"}, + } // Build executor image buildExecutorImage := step{ Name: dockerImage, Args: []string{"build", "-t", executorImage, "-f", "integration_tests/executor/Dockerfile", "."}, } y := testyaml{ - Steps: []step{containerDiffStep, containerDiffPermissions, buildExecutorImage}, + Steps: []step{containerDiffStep, containerDiffPermissions, structureTestsStep, structureTestPermissions, buildExecutorImage}, } - for _, test := range tests { + for _, test := range fileTests { // First, build the image with docker dockerImageTag := testRepo + dockerPrefix + test.repo dockerBuild := step{ @@ -133,6 +155,29 @@ func main() { y.Steps = append(y.Steps, dockerBuild, kbuild, pullKbuildImage, containerDiff, catContainerDiffOutput, compareOutputs) } + for _, test := range structureTests { + // Build the image with kbuild + kbuildImage := testRepo + kbuildPrefix + test.repo + kbuild := step{ + Name: executorImage, + Args: []string{executorCommand, "--destination", kbuildImage, "--dockerfile", test.dockerfilePath}, + } + // Pull the kbuild image + pullKbuildImage := step{ + Name: dockerImage, + Args: []string{"pull", kbuildImage}, + } + // Run structure tests on the image + args := "container-structure-test -image " + kbuildImage + " " + test.structureTestYamlPath + structureTest := step{ + Name: ubuntuImage, + Args: []string{"sh", "-c", args}, + Env: []string{"PATH=/workspace:/bin"}, + } + + y.Steps = append(y.Steps, kbuild, pullKbuildImage, structureTest) + } + d, _ := yaml.Marshal(&y) fmt.Println(string(d)) }