From 32b2dc64d7a1bd61c033151440757577136f826a Mon Sep 17 00:00:00 2001 From: Ellen-Yi-Dong Date: Thu, 29 Aug 2024 15:01:39 -0700 Subject: [PATCH 1/3] Add unit tests to uhc-auth-proxy build pipeline --- .tekton/uhc-auth-proxy-pull-request.yaml | 68 ++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/.tekton/uhc-auth-proxy-pull-request.yaml b/.tekton/uhc-auth-proxy-pull-request.yaml index 277491b..097da74 100644 --- a/.tekton/uhc-auth-proxy-pull-request.yaml +++ b/.tekton/uhc-auth-proxy-pull-request.yaml @@ -160,6 +160,74 @@ spec: workspaces: - name: basic-auth workspace: git-auth + #unit tests + - name: clone-repository-oci-ta + params: + - name: url + value: $(params.git-url) + - name: revision + value: $(params.revision) + - name: ociStorage + # needs to be unique storage name + value: $(params.output-image).git + runAfter: + - init + taskRef: + params: + - name: name + value: git-clone-oci-ta + - name: bundle + value: quay.io/konflux-ci/tekton-catalog/task-git-clone-oci-ta@sha256:0f4360ce144d46171ebd2e8f4d4575539a0600e02208ba5fc9beeb2c27ddfd4c + - name: kind + value: task + resolver: bundles + workspaces: + # use the git-auth workspace for credentials + - name: basic-auth + workspace: git-auth + - name: task-running-unit-tasks + # make sure the task runs after the artifact is created + runAfter: + - clone-repository-oci-ta + params: + # store the trusted artifact + - name: SOURCE_ARTIFACT + value: $(tasks.clone-repository-oci-ta.results.SOURCE_ARTIFACT) + taskSpec: + params: + - description: The Trusted Artifact URI pointing to the artifact with the application source code. + name: SOURCE_ARTIFACT + type: string + volumes: + # New volume to store a copy of the source code accessible only to this Task. + - name: workdir + emptyDir: {} + stepTemplate: + volumeMounts: + - mountPath: /var/workdir + name: workdir + steps: + # Add the trusted artifact to the task volume + - name: use-trusted-artifact + image: quay.io/redhat-appstudio/build-trusted-artifacts:latest@sha256:8391272c4e5011120e9e7fee2c1f339e9405366110bf239dadcbc21e953ce099 + args: + - use + - $(params.SOURCE_ARTIFACT)=/var/workdir/source + - name: task-run + # set the working directory to value from previous step + workingDir: /var/workdir/source + # Use image that suites your use case + image: FROM registry.access.redhat.com/ubi8/go-toolset:latest + securityContext: + # If the task step needs write access to the volume, set the runAsUser to 0 (root). + runAsUser: 0 + script: | + #!/bin/bash + set -ex + # Execute the task + echo "Run unit tests" + bash unit_test.sh + - name: prefetch-dependencies params: - name: input From cc12701a6019123ef1d7af75cfbc41b1da9aefd1 Mon Sep 17 00:00:00 2001 From: Ellen-Yi-Dong Date: Thu, 29 Aug 2024 15:05:19 -0700 Subject: [PATCH 2/3] Clean up syntax error --- .tekton/uhc-auth-proxy-pull-request.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.tekton/uhc-auth-proxy-pull-request.yaml b/.tekton/uhc-auth-proxy-pull-request.yaml index 097da74..e03f3aa 100644 --- a/.tekton/uhc-auth-proxy-pull-request.yaml +++ b/.tekton/uhc-auth-proxy-pull-request.yaml @@ -217,7 +217,7 @@ spec: # set the working directory to value from previous step workingDir: /var/workdir/source # Use image that suites your use case - image: FROM registry.access.redhat.com/ubi8/go-toolset:latest + image: registry.access.redhat.com/ubi8/go-toolset:latest securityContext: # If the task step needs write access to the volume, set the runAsUser to 0 (root). runAsUser: 0 From 0afe38d7780f3749be39351ff8e187eaecc647d2 Mon Sep 17 00:00:00 2001 From: Ellen-Yi-Dong Date: Thu, 29 Aug 2024 15:08:52 -0700 Subject: [PATCH 3/3] create konflux_unit_test.sh and update reference to it --- .tekton/uhc-auth-proxy-pull-request.yaml | 2 +- konflux_unit_test.sh | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 konflux_unit_test.sh diff --git a/.tekton/uhc-auth-proxy-pull-request.yaml b/.tekton/uhc-auth-proxy-pull-request.yaml index e03f3aa..4ed1f40 100644 --- a/.tekton/uhc-auth-proxy-pull-request.yaml +++ b/.tekton/uhc-auth-proxy-pull-request.yaml @@ -226,7 +226,7 @@ spec: set -ex # Execute the task echo "Run unit tests" - bash unit_test.sh + bash konflux_unit_test.sh - name: prefetch-dependencies params: diff --git a/konflux_unit_test.sh b/konflux_unit_test.sh new file mode 100644 index 0000000..b543447 --- /dev/null +++ b/konflux_unit_test.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -exv + +export GO111MODULE="on" +go test -v -race --coverprofile=coverage.txt --covermode=atomic ./... +result=$? + +if [ $result -ne 0 ]; then + echo '=====================================' + echo '==== ✖ ERROR: UNIT TEST FAILED ====' + echo '=====================================' + exit 1 +fi