Added structure tests to integration test to test ENV command
This commit is contained in:
		
							parent
							
								
									ab0fc3802e
								
							
						
					
					
						commit
						76d5d3e2e2
					
				|  | @ -0,0 +1,5 @@ | |||
| FROM gcr.io/distroless/base | ||||
| ENV hey hey | ||||
| ENV PATH /usr/local | ||||
| ENV hey hello | ||||
| ENV first=foo second=foo2 | ||||
|  | @ -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 | ||||
|  | @ -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)) | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue