github.com/anthropics/anthropic-sdk-go@v1.70.1/scripts/mock (about) 1 #!/usr/bin/env bash 2 3 set -e 4 5 cd "$(dirname "$0")/.." 6 7 if [[ -n "$1" && "$1" != '--'* ]]; then 8 URL="$1" 9 shift 10 elif [ -n "$STAINLESS_OPENAPI_SPEC_URL" ]; then 11 URL="$STAINLESS_OPENAPI_SPEC_URL" 12 else 13 # The generator writes the gzip'd spec next to this script; the 14 # cd at the top of scripts/mock puts CWD at the SDK root. 15 SPEC_TMPFILE="$(mktemp)" 16 trap 'rm -f "$SPEC_TMPFILE"' EXIT 17 gunzip -c scripts/mock-spec.json.gz > "$SPEC_TMPFILE" 18 URL="$SPEC_TMPFILE" 19 fi 20 21 echo "==> Starting mock server with URL ${URL}" 22 23 # Run steady mock on the given spec 24 if [ "$1" == "--daemon" ]; then 25 # Pre-install the package so the download doesn't eat into the startup timeout 26 npm exec --package=@stdy/cli@0.22.2 -- steady --version 27 28 npm exec --package=@stdy/cli@0.22.2 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=brackets --validator-form-array-format=brackets --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL" &> .stdy.log & 29 30 # Wait for server to come online via health endpoint (max 30s) 31 echo -n "Waiting for server" 32 attempts=0 33 while ! curl --silent --fail "http://127.0.0.1:4010/_x-steady/health" >/dev/null 2>&1; do 34 if ! kill -0 $! 2>/dev/null; then 35 echo 36 cat .stdy.log 37 exit 1 38 fi 39 attempts=$((attempts + 1)) 40 if [ "$attempts" -ge 300 ]; then 41 echo 42 echo "Timed out waiting for Steady server to start" 43 cat .stdy.log 44 exit 1 45 fi 46 echo -n "." 47 sleep 0.1 48 done 49 50 echo 51 else 52 npm exec --package=@stdy/cli@0.22.2 -- steady --host 127.0.0.1 -p 4010 --validator-query-array-format=brackets --validator-form-array-format=brackets --validator-query-object-format=brackets --validator-form-object-format=brackets "$URL" 53 fi