|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -output=$(curl -s "http://localhost:8080/api/where/current-time.json?key=test" | jq '.data.entry.time') |
| 3 | +# Timeout for curl requests in seconds |
| 4 | +CURL_TIMEOUT=120 |
| 5 | + |
| 6 | +output=$(curl -s --max-time $CURL_TIMEOUT "http://localhost:8080/api/where/current-time.json?key=test" | jq '.data.entry.time') |
4 | 7 |
|
5 | 8 | if [[ ! -z "$output" && "$output" =~ ^[0-9]+$ ]]; then |
6 | 9 | echo "current-time.json endpoint works." |
|
10 | 13 | fi |
11 | 14 |
|
12 | 15 | # Get the first agency from agencies-with-coverage |
13 | | -agency_response=$(curl -s "http://localhost:8080/api/where/agencies-with-coverage.json?key=test") |
| 16 | +agency_response=$(curl -s --max-time $CURL_TIMEOUT "http://localhost:8080/api/where/agencies-with-coverage.json?key=test") |
| 17 | + |
| 18 | +# Debug: Show raw response if empty or small |
| 19 | +if [[ -z "$agency_response" || ${#agency_response} -lt 100 ]]; then |
| 20 | + echo "Debug: Raw agency response: '$agency_response'" |
| 21 | +fi |
| 22 | + |
| 23 | +# Check if response is valid JSON |
| 24 | +if ! echo "$agency_response" | jq empty 2>/dev/null; then |
| 25 | + echo "Error: Invalid JSON response from agencies-with-coverage endpoint" |
| 26 | + echo "Response: $agency_response" |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | + |
14 | 30 | agency_count=$(echo "$agency_response" | jq '.data.list | length') |
15 | 31 |
|
16 | 32 | if [[ "$agency_count" -gt 0 ]]; then |
|
23 | 39 | fi |
24 | 40 |
|
25 | 41 | # Get routes for the agency |
26 | | -routes_response=$(curl -s "http://localhost:8080/api/where/routes-for-agency/${AGENCY_ID}.json?key=test") |
| 42 | +routes_response=$(curl -s --max-time $CURL_TIMEOUT "http://localhost:8080/api/where/routes-for-agency/${AGENCY_ID}.json?key=test") |
27 | 43 | route_count=$(echo "$routes_response" | jq '.data.list | length') |
28 | 44 | if [[ "$route_count" -gt 0 ]]; then |
29 | 45 | echo "routes-for-agency/${AGENCY_ID}.json endpoint works (found $route_count routes)." |
|
35 | 51 | fi |
36 | 52 |
|
37 | 53 | # Get stops for the route |
38 | | -stops_response=$(curl -s "http://localhost:8080/api/where/stops-for-route/${ROUTE_ID}.json?key=test") |
| 54 | +stops_response=$(curl -s --max-time $CURL_TIMEOUT "http://localhost:8080/api/where/stops-for-route/${ROUTE_ID}.json?key=test") |
39 | 55 | route_id_check=$(echo "$stops_response" | jq -r '.data.entry.routeId') |
40 | 56 | if [[ ! -z "$route_id_check" && "$route_id_check" == "$ROUTE_ID" ]]; then |
41 | 57 | echo "stops-for-route/${ROUTE_ID}.json endpoint works." |
|
47 | 63 | fi |
48 | 64 |
|
49 | 65 | # Get stop details |
50 | | -stop_response=$(curl -s "http://localhost:8080/api/where/stop/${STOP_ID}.json?key=test") |
| 66 | +stop_response=$(curl -s --max-time $CURL_TIMEOUT "http://localhost:8080/api/where/stop/${STOP_ID}.json?key=test") |
51 | 67 | stop_id_check=$(echo "$stop_response" | jq -r '.data.entry.id') |
52 | 68 | if [[ ! -z "$stop_id_check" && "$stop_id_check" == "$STOP_ID" ]]; then |
53 | 69 | echo "stop/${STOP_ID}.json endpoint works." |
|
62 | 78 |
|
63 | 79 | # Test stops-for-location using coordinates from the stop |
64 | 80 | LOCATION_URL="http://localhost:8080/api/where/stops-for-location.json?lat=${STOP_LAT}&lon=${STOP_LON}&key=test" |
65 | | -location_response=$(curl -s "$LOCATION_URL") |
| 81 | +location_response=$(curl -s --max-time $CURL_TIMEOUT "$LOCATION_URL") |
66 | 82 | out_of_range=$(echo "$location_response" | jq '.data.outOfRange') |
67 | 83 | stops_found=$(echo "$location_response" | jq '.data.list | length') |
68 | 84 | if [[ ! -z "$out_of_range" && "$out_of_range" == "false" && "$stops_found" -gt 0 ]]; then |
|
75 | 91 | fi |
76 | 92 |
|
77 | 93 | # Test arrivals-and-departures-for-stop endpoint |
78 | | -arrivals_response=$(curl -s "http://localhost:8080/api/where/arrivals-and-departures-for-stop/${STOP_ID}.json?key=test") |
| 94 | +arrivals_response=$(curl -s --max-time $CURL_TIMEOUT "http://localhost:8080/api/where/arrivals-and-departures-for-stop/${STOP_ID}.json?key=test") |
79 | 95 | arrivals_stop_id=$(echo "$arrivals_response" | jq -r '.data.entry.stopId') |
80 | 96 | arrivals_count=$(echo "$arrivals_response" | jq '.data.entry.arrivalsAndDepartures | length // 0') |
81 | 97 |
|
|
0 commit comments