Skip to content

Commit

Permalink
mocks
Browse files Browse the repository at this point in the history
Signed-off-by: Leandro Mendes <[email protected]>
  • Loading branch information
theflockers committed Dec 19, 2024
1 parent a06adf6 commit b131a54
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 19 deletions.
82 changes: 63 additions & 19 deletions internal/tasks/update-fbc-catalog-task/tests/mocks.sh
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit b131a54

Please sign in to comment.