Skip to content

Commit aec54fe

Browse files
chore(internal): allow the mock server port to be set with STAINLESS_MOCK_PORT
1 parent 6ab61ee commit aec54fe

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

scripts/mock

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ set -e
44

55
cd "$(dirname "$0")/.."
66

7+
if [ "$1" == "--install" ]; then
8+
npm exec --package=@stdy/cli@0.22.1 -- steady --version
9+
exit 0
10+
fi
11+
712
if [[ -n "$1" && "$1" != '--'* ]]; then
813
URL="$1"
914
shift
@@ -20,16 +25,18 @@ fi
2025
echo "==> Starting mock server with URL ${URL}"
2126

2227
# Run steady mock on the given spec
28+
MOCK_PORT="${STAINLESS_MOCK_PORT:-4010}"
29+
2330
if [ "$1" == "--daemon" ]; then
2431
# Pre-install the package so the download doesn't eat into the startup timeout
2532
npm exec --package=@stdy/cli@0.22.1 -- steady --version
2633

27-
npm exec --package=@stdy/cli@0.22.1 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL" &> .stdy.log &
34+
npm exec --package=@stdy/cli@0.22.1 -- steady --host 127.0.0.1 -p "$MOCK_PORT" --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL" &> .stdy.log &
2835

2936
# Wait for server to come online via health endpoint (max 30s)
3037
echo -n "Waiting for server"
3138
attempts=0
32-
while ! curl --silent --fail "http://127.0.0.1:4010/_x-steady/health" >/dev/null 2>&1; do
39+
while ! curl --silent --fail "http://127.0.0.1:$MOCK_PORT/_x-steady/health" >/dev/null 2>&1; do
3340
if ! kill -0 $! 2>/dev/null; then
3441
echo
3542
cat .stdy.log
@@ -48,5 +55,5 @@ if [ "$1" == "--daemon" ]; then
4855

4956
echo
5057
else
51-
npm exec --package=@stdy/cli@0.22.1 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL"
58+
npm exec --package=@stdy/cli@0.22.1 -- steady --host 127.0.0.1 -p "$MOCK_PORT" --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL"
5259
fi

scripts/test

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ GREEN='\033[0;32m'
99
YELLOW='\033[0;33m'
1010
NC='\033[0m' # No Color
1111

12+
MOCK_PORT="${STAINLESS_MOCK_PORT:-4010}"
13+
1214
function steady_is_running() {
13-
curl --silent "http://127.0.0.1:4010/_x-steady/health" >/dev/null 2>&1
15+
curl --silent "http://127.0.0.1:$MOCK_PORT/_x-steady/health" >/dev/null 2>&1
1416
}
1517

1618
kill_server_on_port() {
@@ -27,7 +29,7 @@ function is_overriding_api_base_url() {
2729

2830
if ! is_overriding_api_base_url && ! steady_is_running ; then
2931
# When we exit this script, make sure to kill the background mock server process
30-
trap 'kill_server_on_port 4010' EXIT
32+
trap 'kill_server_on_port "$MOCK_PORT"' EXIT
3133

3234
# Start the dev server
3335
./scripts/mock --daemon
@@ -43,7 +45,7 @@ elif ! steady_is_running ; then
4345
echo -e "To run the server, pass in the path or url of your OpenAPI"
4446
echo -e "spec to the steady command:"
4547
echo
46-
echo -e " \$ ${YELLOW}npm exec --package=@stdy/cli@0.22.1 -- steady path/to/your.openapi.yml --host 127.0.0.1 -p 4010 --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets${NC}"
48+
echo -e " \$ ${YELLOW}npm exec --package=@stdy/cli@0.22.1 -- steady path/to/your.openapi.yml --host 127.0.0.1 -p $MOCK_PORT --validator-query-array-format=comma --validator-form-array-format=comma --validator-query-object-format=brackets --validator-form-object-format=brackets${NC}"
4749
echo
4850

4951
exit 1
@@ -52,6 +54,10 @@ else
5254
echo
5355
fi
5456

57+
if [ -n "${STAINLESS_MOCK_PORT:-}" ] && ! is_overriding_api_base_url ; then
58+
export TEST_API_BASE_URL="http://127.0.0.1:$MOCK_PORT"
59+
fi
60+
5561
export DEFER_PYDANTIC_BUILD=false
5662

5763
echo "==> Running tests"

0 commit comments

Comments
 (0)