test(git-tools): cover rollup curl mock behavior

This commit is contained in:
Jarvis
2026-05-26 15:02:04 -05:00
parent 4a7bebb1cc
commit 43b3759ce2
2 changed files with 63 additions and 6 deletions

View File

@@ -37,16 +37,40 @@ set -euo pipefail
printf 'curl %q ' "$@" >> "$PR_MERGE_TEST_LOG"
printf '\n' >> "$PR_MERGE_TEST_LOG"
args=" $* "
out_file=""
write_code=false
prev=""
for arg in "$@"; do
if [[ "$prev" == "-o" ]]; then
out_file="$arg"
prev=""
continue
fi
if [[ "$arg" == "-o" ]]; then
prev="-o"
continue
fi
if [[ "$arg" == "-w" ]]; then
write_code=true
fi
done
emit_response() {
local body="$1"
if [[ -n "$out_file" ]]; then
printf '%s' "$body" > "$out_file"
else
printf '%s' "$body"
fi
if [[ "$write_code" == true ]]; then
printf '200'
fi
}
if [[ "$args" == *"/api/v1/repos/mosaicstack/stack/pulls/123"* && "$args" != *"/api/v1/repos/mosaicstack/stack/pulls/123/merge"* ]]; then
cat <<'JSON'
{"number":123,"title":"mock","state":"open","user":{"login":"tester"},"head":{"ref":"feature/mock"},"base":{"ref":"main"},"labels":[],"assignees":[],"html_url":"https://git.mosaicstack.dev/mosaicstack/stack/pulls/123","mergeable":true}
JSON
emit_response '{"number":123,"title":"mock","state":"open","user":{"login":"tester"},"head":{"ref":"feature/mock"},"base":{"ref":"main"},"labels":[],"assignees":[],"html_url":"https://git.mosaicstack.dev/mosaicstack/stack/pulls/123","mergeable":true}'
exit 0
fi
if [[ "$args" == *"-X POST"* && "$args" == *"/api/v1/repos/mosaicstack/stack/pulls/123/merge"* ]]; then
cat <<'JSON'
{"merged":true,"message":"mock merge complete"}
JSON
emit_response '{"merged":true,"message":"mock merge complete"}'
exit 0
fi
echo "unexpected curl invocation: $*" >&2