cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
bin/check-test-server
50lines · modecode
| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | RED='\033[0;31m' |
| 4 | GREEN='\033[0;32m' |
| 5 | YELLOW='\033[0;33m' |
| 6 | NC='\033[0m' # No Color |
| 7 | |
| 8 | function prism_is_running() { |
| 9 | curl --silent "http://localhost:4010" >/dev/null 2>&1 |
| 10 | } |
| 11 | |
| 12 | function is_overriding_api_base_url() { |
| 13 | [ -n "$TEST_API_BASE_URL" ] |
| 14 | } |
| 15 | |
| 16 | if is_overriding_api_base_url ; then |
| 17 | # If someone is running the tests against the live API, we can trust they know |
| 18 | # what they're doing and exit early. |
| 19 | echo -e "${GREEN}✔ Running tests against ${TEST_API_BASE_URL}${NC}" |
| 20 | |
| 21 | exit 0 |
| 22 | elif prism_is_running ; then |
| 23 | echo -e "${GREEN}✔ Mock prism server is running with your OpenAPI spec${NC}" |
| 24 | echo |
| 25 | |
| 26 | exit 0 |
| 27 | else |
| 28 | echo -e "${RED}ERROR:${NC} The test suite will not run without a mock Prism server" |
| 29 | echo -e "running against your OpenAPI spec." |
| 30 | echo |
| 31 | echo -e "${YELLOW}To fix:${NC}" |
| 32 | echo |
| 33 | echo -e "1. Install Prism (requires Node 16+):" |
| 34 | echo |
| 35 | echo -e " With npm:" |
| 36 | echo -e " \$ ${YELLOW}npm install -g @stoplight/prism-cli${NC}" |
| 37 | echo |
| 38 | echo -e " With yarn:" |
| 39 | echo -e " \$ ${YELLOW}yarn global add @stoplight/prism-cli${NC}" |
| 40 | echo |
| 41 | echo -e "2. Run the mock server" |
| 42 | echo |
| 43 | echo -e " To run the server, pass in the path of your OpenAPI" |
| 44 | echo -e " spec to the prism command:" |
| 45 | echo |
| 46 | echo -e " \$ ${YELLOW}prism mock path/to/your.openapi.yml${NC}" |
| 47 | echo |
| 48 | |
| 49 | exit 1 |
| 50 | fi |
| 51 | |