diff --git a/internal/tasks/update-fbc-catalog-task/tests/mocks.sh b/internal/tasks/update-fbc-catalog-task/tests/mocks.sh index 0f347ec0a..e4d3ce6ca 100755 --- a/internal/tasks/update-fbc-catalog-task/tests/mocks.sh +++ b/internal/tasks/update-fbc-catalog-task/tests/mocks.sh @@ -1,26 +1,70 @@ #!/bin/bash set -eux -# need a seed -SEED=' ---- -id: 1 -distribution_scope: "stage" -fbc_fragment: "registry.io/image0@sha256:0000" -internal_index_image_copy: "registry-proxy-stage.engineering.redhat.com/rh-osbs-stage/iib:1" -logs: -url: "https://fakeiib.host/api/v1/builds/1/logs" -request_type: "fbc-operations" -state: "complete" -state_reason: "" -state_history: - - state: "in_progress" - state_reason: "The request was initiated" -user: "iib@kerberos"' - -success_state_reason="The FBC fragment was successfully added in the index image" +# seed for the build status +yq -o json <<< ' +items: +- id: 1 + distribution_scope: "stage" + fbc_fragment: "registry.io/image0@sha256:0000" + internal_index_image_copy: "registry-proxy-stage.engineering.redhat.com/rh-osbs-stage/iib:1" + logs: + url: "https://fakeiib.host/api/v1/builds/1/logs" + request_type: "fbc-operations" + state: "in_progress" + state_reason: "The request was initiated" + state_history: + - state: "in_progress" + state_reason: "The request was initiated" + user: "iib@kerberos"' > /tmp/build-seed + +buildSeed=$(cat /tmp/build-seed) +export buildSeed + +function mock_build_progress() { + + build="${buildSeed}" + + state_reason[0]="Resolving the fbc fragment" + state_reason[1]="Resolving the container images" + state_reason[2]="Building the index image for the following arches: amd64, arm64, ppc64le, s390x" + state_reason[3]="Extracting operator package from fbc_fragment" + state_reason[4]="Adding fbc_fragment to from_index" + state_reason[5]="Creating the manifest list" + state_reason[6]="The FBC fragment was successfully added in the index image" + + for ((i=0; i<=${state_reason[@]}; i++)); do + if [ $i -eq ${state_reason[@]} ]; then + build=$(jq --jsonargs state_history "{ \"state\": \"complete\", \"state_reason\": \"${state_reason[$i]}\" }" '.state_history += [$state_history]' <<< "${build}") + break + fi + build=$(jq --jsonargs state_history "{ \"state\": \"in_progress\", \"state_reason\": \"${state_reason[$i]}\" }" '.state_history += [$state_history]' <<< "${build}") + let i=$i+1 + sleep 10 + done +} + function curl() { - yq -o json <<< $SEED | jq --argjson progress '{ "state": "completed", "state_reason": "The FBC fragment was successfully added in the index image"}' '.state_history += [$progress]' + shift + case $1 in + "https://fakeiib.host/builds?user=iib@kerberos&from_index=quay.io/scoheb/fbc-index-testing:latest") + echo -en "${buildSeed}" + ;; + "-u:") + tempfile="$4" + echo -e '{}' > "$tempfile" + ;; + "https://fakeiib.host/builds/1") + mock_build_progress + ;; + *) + echo "" + ;; + esac +} + +function opm() { + echo '{ "schema": "olm.bundle", "image": "quay.io/repo/image@sha256:abcd1234"}' } function base64() { diff --git a/internal/tasks/update-fbc-catalog-task/tests/pre-apply-task-hook.sh b/internal/tasks/update-fbc-catalog-task/tests/pre-apply-task-hook.sh index f8f35dd0c..4e5f74572 100755 --- a/internal/tasks/update-fbc-catalog-task/tests/pre-apply-task-hook.sh +++ b/internal/tasks/update-fbc-catalog-task/tests/pre-apply-task-hook.sh @@ -21,3 +21,4 @@ kubectl create secret generic iib-overwrite-fromimage-credentials \ TASK_PATH="$1" SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) yq -i '.spec.steps[0].script = load_str("'$SCRIPT_DIR'/mocks.sh") + .spec.steps[0].script' "$TASK_PATH" +yq -i '.spec.steps[1].script = load_str("'$SCRIPT_DIR'/mocks.sh") + .spec.steps[1].script' "$TASK_PATH"