Skip to content

Commit 5905eea

Browse files
committed
Merge branch 'main' into chore/update-workstation-9.0-from-main
2 parents 8f82bd3 + 6ef2319 commit 5905eea

File tree

1 file changed

+57
-56
lines changed

1 file changed

+57
-56
lines changed

IntegrationTests/run_integration_tests_ci.sh

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/bin/bash
2+
# shellcheck disable=SC2155
3+
# shellcheck disable=SC2312
24
# CI-specific integration test script that runs WireMock as a Java process
35
# instead of Docker (for GitHub Actions macOS runners)
46
set -e
@@ -29,11 +31,11 @@ escape_mapping_bodies() {
2931
echo "🔄 Converting mapping bodies to escaped format (WireMock-compatible)..."
3032
local MAPPINGS_FILES="${MAPPINGS_DIR}/mappings"
3133

32-
if [ -d "$MAPPINGS_FILES" ] && [ "$(ls -A $MAPPINGS_FILES/*.json 2>/dev/null)" ]; then
33-
for mapping_file in "$MAPPINGS_FILES"/*.json; do
34-
if [ -f "$mapping_file" ]; then
35-
python3 transform_mapping_body.py "$mapping_file" escape >/dev/null 2>&1 || {
36-
echo "⚠️ Failed to escape $(basename $mapping_file)"
34+
if [[ -d ${MAPPINGS_FILES} ]] && [[ -n "$(ls -A "${MAPPINGS_FILES}"/*.json 2>/dev/null)" ]]; then
35+
for mapping_file in "${MAPPINGS_FILES}"/*.json; do
36+
if [[ -f ${mapping_file} ]]; then
37+
python3 transform_mapping_body.py "${mapping_file}" escape >/dev/null 2>&1 || {
38+
echo "⚠️ Failed to escape $(basename "${mapping_file}")"
3739
}
3840
fi
3941
done
@@ -44,11 +46,11 @@ unescape_mapping_bodies() {
4446
echo "🔄 Converting mapping bodies back to unescaped format (readable)..."
4547
local MAPPINGS_FILES="${MAPPINGS_DIR}/mappings"
4648

47-
if [ -d "$MAPPINGS_FILES" ] && [ "$(ls -A $MAPPINGS_FILES/*.json 2>/dev/null)" ]; then
48-
for mapping_file in "$MAPPINGS_FILES"/*.json; do
49-
if [ -f "$mapping_file" ]; then
50-
python3 transform_mapping_body.py "$mapping_file" unescape >/dev/null 2>&1 || {
51-
echo "⚠️ Failed to unescape $(basename $mapping_file)"
49+
if [[ -d ${MAPPINGS_FILES} ]] && [[ -n "$(ls -A "${MAPPINGS_FILES}"/*.json 2>/dev/null)" ]]; then
50+
for mapping_file in "${MAPPINGS_FILES}"/*.json; do
51+
if [[ -f ${mapping_file} ]]; then
52+
python3 transform_mapping_body.py "${mapping_file}" unescape >/dev/null 2>&1 || {
53+
echo "⚠️ Failed to unescape $(basename "${mapping_file}")"
5254
}
5355
fi
5456
done
@@ -62,8 +64,8 @@ start_wiremock_java() {
6264
stop_wiremock_java
6365

6466
# Check if JAR exists
65-
if [ ! -f "$WIREMOCK_JAR" ]; then
66-
echo "❌ WireMock JAR not found at: $WIREMOCK_JAR"
67+
if [[ ! -f ${WIREMOCK_JAR} ]]; then
68+
echo "❌ WireMock JAR not found at: ${WIREMOCK_JAR}"
6769
exit 1
6870
fi
6971

@@ -72,37 +74,36 @@ start_wiremock_java() {
7274

7375
# Start WireMock in background
7476
# Use sudo if HTTPS_PORT is privileged (< 1024)
75-
if [ "$HTTPS_PORT" -lt 1024 ]; then
77+
if [[ ${HTTPS_PORT} -lt 1024 ]]; then
7678
echo "ℹ️ Using sudo to bind to privileged port ${HTTPS_PORT}"
77-
sudo java -jar "$WIREMOCK_JAR" \
78-
--port ${HTTP_PORT} \
79-
--https-port ${HTTPS_PORT} \
79+
sudo java -jar "${WIREMOCK_JAR}" \
80+
--port "${HTTP_PORT}" \
81+
--https-port "${HTTPS_PORT}" \
8082
--root-dir "${ABS_MAPPINGS_DIR}" \
81-
--verbose \
82-
>"$WIREMOCK_LOG_FILE" 2>&1 &
83+
--verbose 2>&1 | sudo tee "${WIREMOCK_LOG_FILE}" >/dev/null &
8384
else
84-
java -jar "$WIREMOCK_JAR" \
85-
--port ${HTTP_PORT} \
86-
--https-port ${HTTPS_PORT} \
85+
java -jar "${WIREMOCK_JAR}" \
86+
--port "${HTTP_PORT}" \
87+
--https-port "${HTTPS_PORT}" \
8788
--root-dir "${ABS_MAPPINGS_DIR}" \
8889
--verbose \
89-
>"$WIREMOCK_LOG_FILE" 2>&1 &
90+
>"${WIREMOCK_LOG_FILE}" 2>&1 &
9091
fi
9192

92-
echo $! >"$WIREMOCK_PID_FILE"
93-
echo "✅ WireMock started with PID: $(cat $WIREMOCK_PID_FILE)"
93+
echo $! >"${WIREMOCK_PID_FILE}"
94+
echo "✅ WireMock started with PID: $(cat "${WIREMOCK_PID_FILE}")"
9495
}
9596

9697
stop_wiremock_java() {
97-
if [ -f "$WIREMOCK_PID_FILE" ]; then
98-
local pid=$(cat "$WIREMOCK_PID_FILE")
99-
if kill -0 "$pid" 2>/dev/null; then
100-
echo "🛑 Stopping WireMock (PID: $pid)..."
101-
kill "$pid" 2>/dev/null || sudo kill "$pid" 2>/dev/null || true
98+
if [[ -f ${WIREMOCK_PID_FILE} ]]; then
99+
local pid=$(cat "${WIREMOCK_PID_FILE}")
100+
if kill -0 "${pid}" 2>/dev/null; then
101+
echo "🛑 Stopping WireMock (PID: ${pid})..."
102+
kill "${pid}" 2>/dev/null || sudo kill "${pid}" 2>/dev/null || true
102103
sleep 2
103-
kill -9 "$pid" 2>/dev/null || sudo kill -9 "$pid" 2>/dev/null || true
104+
kill -9 "${pid}" 2>/dev/null || sudo kill -9 "${pid}" 2>/dev/null || true
104105
fi
105-
rm -f "$WIREMOCK_PID_FILE"
106+
rm -f "${WIREMOCK_PID_FILE}"
106107
fi
107108
# Also try to kill any remaining WireMock processes (may need sudo if started with sudo)
108109
pkill -f "wiremock" 2>/dev/null || true
@@ -132,15 +133,15 @@ wait_for_wiremock_java() {
132133

133134
echo "❌ WireMock failed to start within ${MAX_RETRIES} seconds"
134135
echo "📋 WireMock logs:"
135-
cat "$WIREMOCK_LOG_FILE" || true
136+
cat "${WIREMOCK_LOG_FILE}" || true
136137
exit 1
137138
}
138139

139140
show_wiremock_logs_java() {
140141
echo ""
141142
echo "📋 WireMock logs:"
142143
echo "════════════════════════════════════════════════════════════════"
143-
cat "$WIREMOCK_LOG_FILE" 2>/dev/null || echo "❌ Could not retrieve logs"
144+
cat "${WIREMOCK_LOG_FILE}" 2>/dev/null || echo "❌ Could not retrieve logs"
144145
echo "════════════════════════════════════════════════════════════════"
145146
echo ""
146147
}
@@ -153,22 +154,22 @@ verify_wiremock_results() {
153154
local WIREMOCK_PORT=${HTTP_PORT}
154155

155156
# Count all requests
156-
local TOTAL=$(curl -s http://localhost:${WIREMOCK_PORT}/__admin/requests | jq '.requests | length')
157-
local UNMATCHED=$(curl -s http://localhost:${WIREMOCK_PORT}/__admin/requests/unmatched | jq '.requests | length')
157+
local TOTAL=$(curl -s http://localhost:"${WIREMOCK_PORT}"/__admin/requests | jq '.requests | length')
158+
local UNMATCHED=$(curl -s http://localhost:"${WIREMOCK_PORT}"/__admin/requests/unmatched | jq '.requests | length')
158159
local MATCHED=$((TOTAL - UNMATCHED))
159160

160161
echo "📊 WireMock summary:"
161162
echo "──────────────────────────────"
162-
echo " Total requests: $TOTAL"
163-
echo " Matched requests: $MATCHED"
164-
echo " Unmatched requests: $UNMATCHED"
163+
echo " Total requests: ${TOTAL}"
164+
echo " Matched requests: ${MATCHED}"
165+
echo " Unmatched requests: ${UNMATCHED}"
165166
echo "──────────────────────────────"
166167
echo ""
167168

168169
# Check for unmatched requests
169-
if [ "$UNMATCHED" -gt 0 ]; then
170+
if [[ ${UNMATCHED} -gt 0 ]]; then
170171
echo "❌ Found requests that did not match any mappings:"
171-
curl -s http://localhost:${WIREMOCK_PORT}/__admin/requests/unmatched |
172+
curl -s http://localhost:"${WIREMOCK_PORT}"/__admin/requests/unmatched |
172173
jq -r '.requests[] | " [\(.method)] \(.url)"'
173174
echo ""
174175
show_wiremock_logs_java
@@ -182,41 +183,41 @@ verify_wiremock_results() {
182183
echo ""
183184
echo "🧩 Checking: were all mappings invoked..."
184185

185-
local EXPECTED_MAPPINGS=$(jq -r 'select(.response.proxyBaseUrl == null) | "\(.request.method // "ANY") \(.request.url // .request.urlPattern // .request.urlPath // .request.urlPathPattern)"' ${MAPPINGS_DIR}/mappings/*.json 2>/dev/null | sort)
186+
local EXPECTED_MAPPINGS=$(jq -r 'select(.response.proxyBaseUrl == null) | "\(.request.method // "ANY") \(.request.url // .request.urlPattern // .request.urlPath // .request.urlPathPattern)"' "${MAPPINGS_DIR}"/mappings/*.json 2>/dev/null | sort)
186187

187-
local ACTUAL_REQUESTS=$(curl -s http://localhost:${WIREMOCK_PORT}/__admin/requests |
188+
local ACTUAL_REQUESTS=$(curl -s http://localhost:"${WIREMOCK_PORT}"/__admin/requests |
188189
jq -r '.requests[] | "\(.request.method) \(.request.url)"' | sort | uniq)
189190

190191
local UNUSED_FOUND=false
191192
while IFS= read -r mapping; do
192-
if [ -n "$mapping" ]; then
193-
local method=$(echo "$mapping" | awk '{print $1}')
194-
local url=$(echo "$mapping" | awk '{$1=""; print $0}' | sed 's/^ //')
193+
if [[ -n ${mapping} ]]; then
194+
local method=$(echo "${mapping}" | awk '{print $1}')
195+
local url=$(echo "${mapping}" | awk '{$1=""; print $0}' | sed 's/^ //')
195196

196197
local matched=false
197198

198-
if echo "$url" | grep -q '\[' || echo "$url" | grep -q '\\'; then
199-
local url_start=$(echo "$url" | cut -d'[' -f1 | cut -d'\' -f1)
200-
if echo "$ACTUAL_REQUESTS" | grep -Fq "$method $url_start"; then
199+
if echo "${url}" | grep -q '\[' || echo "${url}" | grep -Fq $'\\'; then
200+
local url_start=$(echo "${url}" | cut -d'[' -f1 | cut -d $'\\' -f1)
201+
if echo "${ACTUAL_REQUESTS}" | grep -Fq "${method} ${url_start}"; then
201202
matched=true
202203
fi
203204
else
204-
if echo "$ACTUAL_REQUESTS" | grep -Fq "$mapping"; then
205+
if echo "${ACTUAL_REQUESTS}" | grep -Fq "${mapping}"; then
205206
matched=true
206207
fi
207208
fi
208209

209-
if [ "$matched" = false ]; then
210-
if [ "$UNUSED_FOUND" = false ]; then
210+
if [[ ${matched} == false ]]; then
211+
if [[ ${UNUSED_FOUND} == false ]]; then
211212
echo "⚠️ Some mappings were not invoked by the application:"
212213
UNUSED_FOUND=true
213214
fi
214-
echo " $mapping"
215+
echo " ${mapping}"
215216
fi
216217
fi
217-
done <<<"$EXPECTED_MAPPINGS"
218+
done <<<"${EXPECTED_MAPPINGS}"
218219

219-
if [ "$UNUSED_FOUND" = false ]; then
220+
if [[ ${UNUSED_FOUND} == false ]]; then
220221
echo "✅ All recorded mappings were invoked by the application."
221222
fi
222223

@@ -234,11 +235,11 @@ cleanup() {
234235
error_handler() {
235236
local exit_code=$?
236237
echo ""
237-
echo "❌ Script failed with exit code: $exit_code"
238+
echo "❌ Script failed with exit code: ${exit_code}"
238239
show_wiremock_logs_java
239240
unescape_mapping_bodies
240241
stop_wiremock_java
241-
exit $exit_code
242+
exit "${exit_code}"
242243
}
243244

244245
# Trap to ensure cleanup on exit or error

0 commit comments

Comments
 (0)