Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
Signed-off-by: Leandro Mendes <[email protected]>
  • Loading branch information
theflockers committed Dec 20, 2024
1 parent 40a11ad commit 237a799
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 2 deletions.
5 changes: 3 additions & 2 deletions internal/tasks/update-fbc-catalog-task/tests/mocks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function curl() {
;;
"-u:")
tempfile="$4"
echo -e '{}' > "$tempfile"
echo -e '{ "fbc_opt_in": true}' > "$tempfile"
;;
"https://fakeiib.host/builds/1")
echo "$@" >> mock_build_progress_calls
Expand All @@ -70,7 +70,8 @@ function curl() {
echo "Logs are for weaks"
;;
":")
echo -en "${buildJson} | jq -cr"
set -x
echo -en "${buildJson}" | jq -cr
;;
*)
echo ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ spec:
exit 1
fi
# shellcheck disable=SC2046
genericResult=$(jq -r \
'. |[.fbc_opt_in, .overwrite_fromindex_image, .publish_index_image,.sign_index_image] |@csv' \
<<< $(params.genericResult))
if [ "$genericResult" != '"true","true","true","true"' ]; then
echo "The stask did not save the correct values in genericResult result"
exit 1
fi
if [ "$(params.indexImageDigests)" != "sha256:000" ]; then
echo "The task did not save a valid digest image in the indexImageDigests result"
exit 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: test-update-fbc-catalog-hotfix
spec:
description: Test
tasks:
- name: run-task
taskRef:
name: update-fbc-catalog-task
params:
- name: fbcFragment
value: "registry.io/image0@sha256:0000"
- name: fromIndex
value: "quay.io/scoheb/fbc-index-testing:latest"
- name: targetIndex
value: "quay.io/fbc/catalog:test"
- name: buildTags
value: "[]"
- name: addArches
value: "[]"
- name: iibServiceAccountSecret
value: "iib-service-account-secret"
- name: hotfix
value: "true"
- name: check-result
params:
- name: jsonBuildInfo
value: $(tasks.run-task.results.jsonBuildInfo)
- name: buildState
value: $(tasks.run-task.results.buildState)
- name: genericResult
value: $(tasks.run-task.results.genericResult)
- name: indexImageDigests
value: $(tasks.run-task.results.indexImageDigests)
- name: iibLog
value: $(tasks.run-task.results.iibLog)
- name: exitCode
value: $(tasks.run-task.results.exitCode)
taskSpec:
params:
- name: jsonBuildInfo
type: string
- name: buildState
type: string
- name: genericResult
type: string
- name: indexImageDigests
type: string
- name: iibLog
type: string
- name: exitCode
type: string
steps:
- name: check-result
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
script: |
#!/bin/bash
set -x
# the jsonBuild mockes has 9 keys on it
keyLength=$(jq '. | length' <<< '$(params.jsonBuildInfo)')
if [ "$keyLength" -ne 9 ]; then
echo "The task did not save a valid json in jsonBuildInfo result"
exit 1
fi
# shellcheck disable=SC2046
state="$(jq -cr '.state' <<< $(params.buildState))"
if [ "$state" != "complete" ]; then
echo "The task did not save a completed IIB build in buildState result"
exit 1
fi
if [ "$(params.indexImageDigests)" != "sha256:000" ]; then
echo "The task did not save a valid digest image in the indexImageDigests result"
exit 1
fi
iibLog=$(awk '{match($0, /https.*/); print(substr($0, RSTART)) }' <<< "$(params.iibLog)")
if [ "$iibLog" != "https://fakeiib.host/api/v1/builds/1/logs" ]; then
echo "The task did not save a valid iib log url in the iibLog result"
exit 1
fi
# shellcheck disable=SC2046
genericResult=$(jq -r \
'. |[.fbc_opt_in, .overwrite_fromindex_image, .publish_index_image, .sign_index_image] |@csv' \
<<< $(params.genericResult))
if [ "$genericResult" != '"true","false","true","true"' ]; then
echo "The stask did not save the correct values in genericResult result"
exit 1
fi
if [ "$(params.exitCode)" != "0" ]; then
echo "The task did not finish with a successful exit code"
exit 1
fi
runAfter:
- run-task
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: test-update-fbc-catalog-staged-index
spec:
description: Test
tasks:
- name: run-task
taskRef:
name: update-fbc-catalog-task
params:
- name: fbcFragment
value: "registry.io/image0@sha256:0000"
- name: fromIndex
value: "quay.io/scoheb/fbc-index-testing:latest"
- name: targetIndex
value: "quay.io/fbc/catalog:test"
- name: buildTags
value: "[]"
- name: addArches
value: "[]"
- name: iibServiceAccountSecret
value: "iib-service-account-secret"
- name: stagedIndex
value: "true"
- name: check-result
params:
- name: jsonBuildInfo
value: $(tasks.run-task.results.jsonBuildInfo)
- name: buildState
value: $(tasks.run-task.results.buildState)
- name: genericResult
value: $(tasks.run-task.results.genericResult)
- name: indexImageDigests
value: $(tasks.run-task.results.indexImageDigests)
- name: iibLog
value: $(tasks.run-task.results.iibLog)
- name: exitCode
value: $(tasks.run-task.results.exitCode)
taskSpec:
params:
- name: jsonBuildInfo
type: string
- name: buildState
type: string
- name: genericResult
type: string
- name: indexImageDigests
type: string
- name: iibLog
type: string
- name: exitCode
type: string
steps:
- name: check-result
image: quay.io/konflux-ci/release-service-utils:e633d51cd41d73e4b3310face21bb980af7a662f
script: |
#!/bin/bash
set -x
# the jsonBuild mockes has 9 keys on it
keyLength=$(jq '. | length' <<< '$(params.jsonBuildInfo)')
if [ "$keyLength" -ne 9 ]; then
echo "The task did not save a valid json in jsonBuildInfo result"
exit 1
fi
# shellcheck disable=SC2046
state="$(jq -cr '.state' <<< $(params.buildState))"
if [ "$state" != "complete" ]; then
echo "The task did not save a completed IIB build in buildState result"
exit 1
fi
# shellcheck disable=SC2046
genericResult=$(jq -r \
'. |[.fbc_opt_in, .overwrite_fromindex_image, .publish_index_image,.sign_index_image] |@csv' \
<<< $(params.genericResult))
if [ "$genericResult" != '"true","false","false","false"' ]; then
echo "The stask did not save the correct values in genericResult result"
exit 1
fi
if [ "$(params.indexImageDigests)" != "sha256:000" ]; then
echo "The task did not save a valid digest image in the indexImageDigests result"
exit 1
fi
iibLog=$(awk '{match($0, /https.*/); print(substr($0, RSTART)) }' <<< "$(params.iibLog)")
if [ "$iibLog" != "https://fakeiib.host/api/v1/builds/1/logs" ]; then
echo "The task did not save a valid iib log url in the iibLog result"
exit 1
fi
if [ "$(params.exitCode)" != "0" ]; then
echo "The task did not finish with a successful exit code"
exit 1
fi
runAfter:
- run-task
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,20 @@ spec:
fi
echo "Fragment has \`fbc_opt_in==${fbcOptIn}\`"
echo " \`mustOverwriteFromIndexImage==${mustOverwriteFromIndexImage}\`"
echo " \`mustPublishIndexImage==${mustPublishIndexImage}\`"
echo " \`mustSignIndexImage==${mustSignIndexImage}\`"
# these results will be used by add-fbc-contribution to control
# signing and publishing of the built fragment
jq -n -c \
--arg fbc_opt_in "${fbcOptIn}" \
--arg overwrite_fromindex_image "${mustOverwriteFromIndexImage}" \
--arg publish_index_image "${mustPublishIndexImage}" \
--arg sign_index_image "${mustSignIndexImage}" \
'{
"fbc_opt_in": $fbc_opt_in,
"overwrite_fromindex_image": $overwrite_fromindex_image,
"publish_index_image": $publish_index_image,
"sign_index_image": $sign_index_image
} | tostring' | tee "$(results.genericResult.path)"
Expand Down

0 comments on commit 237a799

Please sign in to comment.