2024-04-26 16:30:06 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
2024-04-30 11:36:38 -04:00
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
cd "$(dirname "$0")/.."
|
|
|
|
|
|
2024-04-30 23:59:44 -04:00
|
|
|
if [[ -n "$1" && "$1" != '--'* ]]; then
|
2024-04-26 16:30:06 -04:00
|
|
|
URL="$1"
|
|
|
|
|
shift
|
|
|
|
|
else
|
|
|
|
|
URL="$(grep 'openapi_spec_url' .stats.yml | cut -d' ' -f2)"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Check if the URL is empty
|
|
|
|
|
if [ -z "$URL" ]; then
|
|
|
|
|
echo "Error: No OpenAPI spec path/url provided or found in .stats.yml"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2024-04-30 23:59:44 -04:00
|
|
|
echo "==> Starting mock server with URL ${URL}"
|
|
|
|
|
|
2026-03-19 18:59:08 +00:00
|
|
|
# Run steady mock on the given spec
|
2024-04-26 16:30:06 -04:00
|
|
|
if [ "$1" == "--daemon" ]; then
|
2026-03-05 13:02:43 +00:00
|
|
|
# Pre-install the package so the download doesn't eat into the startup timeout
|
2026-03-24 15:43:54 +00:00
|
|
|
npm exec --package=@stdy/cli@0.19.7 -- steady --version
|
2026-03-05 13:02:43 +00:00
|
|
|
|
2026-03-24 15:43:54 +00:00
|
|
|
npm exec --package=@stdy/cli@0.19.7 -- steady --host 127.0.0.1 -p 4010 --validator-form-array-format=brackets --validator-query-array-format=brackets --validator-form-object-format=brackets --validator-query-object-format=brackets "$URL" &> .stdy.log &
|
2024-04-26 16:30:06 -04:00
|
|
|
|
2026-03-19 18:59:08 +00:00
|
|
|
# Wait for server to come online via health endpoint (max 30s)
|
2024-04-30 23:59:44 -04:00
|
|
|
echo -n "Waiting for server"
|
2026-03-05 13:02:43 +00:00
|
|
|
attempts=0
|
2026-03-19 18:59:08 +00:00
|
|
|
while ! curl --silent --fail "http://127.0.0.1:4010/_x-steady/health" >/dev/null 2>&1; do
|
|
|
|
|
if ! kill -0 $! 2>/dev/null; then
|
|
|
|
|
echo
|
|
|
|
|
cat .stdy.log
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2026-03-05 13:02:43 +00:00
|
|
|
attempts=$((attempts + 1))
|
|
|
|
|
if [ "$attempts" -ge 300 ]; then
|
|
|
|
|
echo
|
2026-03-19 18:59:08 +00:00
|
|
|
echo "Timed out waiting for Steady server to start"
|
|
|
|
|
cat .stdy.log
|
2026-03-05 13:02:43 +00:00
|
|
|
exit 1
|
|
|
|
|
fi
|
2024-04-26 16:30:06 -04:00
|
|
|
echo -n "."
|
|
|
|
|
sleep 0.1
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
echo
|
|
|
|
|
else
|
2026-03-24 15:43:54 +00:00
|
|
|
npm exec --package=@stdy/cli@0.19.7 -- steady --host 127.0.0.1 -p 4010 --validator-form-array-format=brackets --validator-query-array-format=brackets --validator-form-object-format=brackets --validator-query-object-format=brackets "$URL"
|
2024-04-26 16:30:06 -04:00
|
|
|
fi
|