Skip to content

Commit

Permalink
Merge pull request #88 from Ellen-Yi-Dong/add_unit_tests
Browse files Browse the repository at this point in the history
Add unit tests to uhc-auth-proxy build pipeline
  • Loading branch information
Ellen-Yi-Dong authored Aug 30, 2024
2 parents a7a2915 + 0afe38d commit af63322
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
68 changes: 68 additions & 0 deletions .tekton/uhc-auth-proxy-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: 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 konflux_unit_test.sh
- name: prefetch-dependencies
params:
- name: input
Expand Down
14 changes: 14 additions & 0 deletions konflux_unit_test.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit af63322

Please sign in to comment.