|
| 1 | +//go:build e2e |
| 2 | +// +build e2e |
| 3 | + |
| 4 | +package dockerfile_inputs |
| 5 | + |
| 6 | +import ( |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/openshift/ci-tools/test/e2e/framework" |
| 10 | +) |
| 11 | + |
| 12 | +func TestDockerfileInputs(t *testing.T) { |
| 13 | + const defaultJobSpec = `{"type":"postsubmit","job":"branch-ci-test-test-master-dockerfile-inputs","buildid":"0","prowjobid":"uuid","refs":{"org":"test","repo":"test","base_ref":"master","base_sha":"6d231cc37652e85e0f0e25c21088b73d644d89ad","pulls":[]},"decoration_config":{"timeout":"4h0m0s","grace_period":"30m0s","utility_images":{"clonerefs":"quay-proxy.ci.openshift.org/openshift/ci:ci_clonerefs_latest","initupload":"quay-proxy.ci.openshift.org/openshift/ci:ci_initupload_latest","entrypoint":"quay-proxy.ci.openshift.org/openshift/ci:ci_entrypoint_latest","sidecar":"quay-proxy.ci.openshift.org/openshift/ci:ci_sidecar_latest"},"resources":{"clonerefs":{"limits":{"memory":"3Gi"},"requests":{"cpu":"100m","memory":"500Mi"}},"initupload":{"limits":{"memory":"200Mi"},"requests":{"cpu":"100m","memory":"50Mi"}},"place_entrypoint":{"limits":{"memory":"100Mi"},"requests":{"cpu":"100m","memory":"25Mi"}},"sidecar":{"limits":{"memory":"2Gi"},"requests":{"cpu":"100m","memory":"250Mi"}}},"gcs_configuration":{"bucket":"test-platform-results","path_strategy":"single","default_org":"openshift","default_repo":"origin","mediaTypes":{"log":"text/plain"}},"gcs_credentials_secret":"gce-sa-credentials-gcs-publisher"}}` |
| 14 | + |
| 15 | + var testCases = []struct { |
| 16 | + name string |
| 17 | + args []string |
| 18 | + success bool |
| 19 | + output []string |
| 20 | + }{ |
| 21 | + { |
| 22 | + name: "auto-detect single registry.ci.openshift.org reference", |
| 23 | + args: []string{"--target=auto-detect-single"}, |
| 24 | + success: true, |
| 25 | + output: []string{ |
| 26 | + "Dockerfile-inputs: Detected registry reference", |
| 27 | + "registry.ci.openshift.org/ocp/4.19:base", |
| 28 | + }, |
| 29 | + }, |
| 30 | + { |
| 31 | + name: "auto-detect multiple registry references", |
| 32 | + args: []string{"--target=auto-detect-multiple"}, |
| 33 | + success: true, |
| 34 | + output: []string{ |
| 35 | + "Dockerfile-inputs: Detected registry reference", |
| 36 | + "registry.ci.openshift.org/ocp/4.19:base", |
| 37 | + "registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.22-openshift-4.19", |
| 38 | + }, |
| 39 | + }, |
| 40 | + { |
| 41 | + name: "auto-detect with quay-proxy reference", |
| 42 | + args: []string{"--target=auto-detect-quay-proxy"}, |
| 43 | + success: true, |
| 44 | + output: []string{ |
| 45 | + "Dockerfile-inputs: Detected registry reference", |
| 46 | + "quay-proxy.ci.openshift.org/openshift/ci:ocp_builder_rhel-9-golang-1.22-openshift-4.19", |
| 47 | + }, |
| 48 | + }, |
| 49 | + { |
| 50 | + name: "skip auto-detect when manual inputs.as defined", |
| 51 | + args: []string{"--target=manual-inputs"}, |
| 52 | + success: true, |
| 53 | + output: []string{ |
| 54 | + "Skipping Dockerfile inputs detection: manual inputs defined", |
| 55 | + "registry.ci.openshift.org/ocp/4.19:base", |
| 56 | + }, |
| 57 | + }, |
| 58 | + { |
| 59 | + name: "auto-detect with COPY --from reference", |
| 60 | + args: []string{"--target=auto-detect-copy-from"}, |
| 61 | + success: true, |
| 62 | + output: []string{ |
| 63 | + "Dockerfile-inputs: Detected registry reference", |
| 64 | + "registry.ci.openshift.org/ocp/4.19:base", |
| 65 | + }, |
| 66 | + }, |
| 67 | + { |
| 68 | + name: "no auto-detect when no registry references", |
| 69 | + args: []string{"--target=no-registry-refs"}, |
| 70 | + success: true, |
| 71 | + output: []string{}, |
| 72 | + }, |
| 73 | + } |
| 74 | + |
| 75 | + for _, testCase := range testCases { |
| 76 | + testCase := testCase |
| 77 | + framework.Run(t, testCase.name, func(t *framework.T, cmd *framework.CiOperatorCommand) { |
| 78 | + cmd.AddArgs(framework.LocalPullSecretFlag(t), framework.RemotePullSecretFlag(t)) |
| 79 | + cmd.AddArgs(append(testCase.args, "--config=config.yaml")...) |
| 80 | + cmd.AddEnv("JOB_SPEC=" + defaultJobSpec) |
| 81 | + output, err := cmd.Run() |
| 82 | + if testCase.success != (err == nil) { |
| 83 | + t.Fatalf("%s: didn't expect an error from ci-operator: %v; output:\n%v", testCase.name, err, string(output)) |
| 84 | + } |
| 85 | + if len(testCase.output) > 0 { |
| 86 | + cmd.VerboseOutputContains(t, testCase.name, testCase.output...) |
| 87 | + } |
| 88 | + }) |
| 89 | + } |
| 90 | +} |
0 commit comments