Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ jobs:
run: go mod verify

- name: Check OpenAPI spec is up to date with upstream
if: matrix.os == 'ubuntu-latest'
run: make check-openapi
run: bash scripts/check-openapi.sh
shell: bash

- name: Run tests (fast mode)
Expand Down
18 changes: 2 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,12 @@ models:

# Fetch the latest upstream OpenAPI spec and overwrite testdata/openapi.yml.
update-openapi:
@echo "Fetching upstream OpenAPI spec from sdk-config..."
curl -sSfL "https://raw.githubusercontent.com/OneBusAway/sdk-config/main/openapi.yml" \
-o /tmp/openapi.latest.yml
@printf '# Source: https://github.com/OneBusAway/sdk-config/blob/main/openapi.yml\n# Fetched: %s\n' "$$(date +%Y-%m-%d)" > testdata/openapi.yml
cat /tmp/openapi.latest.yml >> testdata/openapi.yml
@echo "Updated testdata/openapi.yml"
bash scripts/update-openapi.sh

# Check whether testdata/openapi.yml matches the live upstream (skipping header).
# Exits 1 if out of date (useful for CI checks).
check-openapi:
@echo "Checking upstream OpenAPI spec for changes..."
@curl -sSfL "https://raw.githubusercontent.com/OneBusAway/sdk-config/main/openapi.yml" \
-o /tmp/openapi.check.yml
@if tail -n +3 testdata/openapi.yml | cmp -s /tmp/openapi.check.yml -; then \
echo "openapi.yml is up to date with upstream"; \
else \
echo "WARNING: upstream openapi.yml has changed. Run 'make update-openapi' to update."; \
echo "If you find issues in the upstream spec, please open an issue at: https://github.com/OneBusAway/sdk-config/issues"; \
exit 1; \
fi
bash scripts/check-openapi.sh

watch:
air
Expand Down
7 changes: 3 additions & 4 deletions internal/restapi/block_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,18 +514,17 @@ func TestBlockHandlerContextCancellation(t *testing.T) {
req, err := http.NewRequest("GET", "/api/where/block/25_1.json?key=TEST", nil)
require.NoError(t, err)

ctx, cancel := context.WithTimeout(context.Background(), 1*time.Nanosecond)
// Use a deadline in the past — context.Err() is DeadlineExceeded immediately,
// no timer resolution dependency (avoids Windows ~15ms minimum sleep issue).
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(-1*time.Second))
defer cancel()
req = req.WithContext(ctx)

time.Sleep(time.Microsecond)

w := httptest.NewRecorder()
mux := http.NewServeMux()
api.SetRoutes(mux)
mux.ServeHTTP(w, req)

// With a 1ns timeout and 1µs sleep the context is always DeadlineExceeded
assert.Equal(t, http.StatusGatewayTimeout, w.Code,
"Expected 504 Gateway Timeout for DeadlineExceeded context, got: %d", w.Code)
})
Expand Down
21 changes: 21 additions & 0 deletions scripts/check-openapi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -euo pipefail

UPSTREAM_URL="https://raw.githubusercontent.com/OneBusAway/sdk-config/main/openapi.yml"
LOCAL="testdata/openapi.yml"
TMP="$(mktemp /tmp/openapi.XXXXXX.yml)"

cleanup() { rm -f "$TMP"; }
trap cleanup EXIT

echo "Checking upstream OpenAPI spec for changes..."
curl -sSfL "$UPSTREAM_URL" -o "$TMP"

# Skip the 2-line header when comparing
if tail -n +3 "$LOCAL" | cmp -s "$TMP" -; then
echo "openapi.yml is up to date with upstream"
else
echo "WARNING: upstream openapi.yml has changed. Run 'make update-openapi' to update."
echo "If you find issues in the upstream spec, open an issue at: https://github.com/OneBusAway/sdk-config/issues"
exit 1
fi
17 changes: 17 additions & 0 deletions scripts/update-openapi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail

UPSTREAM_URL="https://raw.githubusercontent.com/OneBusAway/sdk-config/main/openapi.yml"
DEST="testdata/openapi.yml"
TMP="$(mktemp /tmp/openapi.XXXXXX.yml)"

cleanup() { rm -f "$TMP"; }
trap cleanup EXIT

echo "Fetching upstream OpenAPI spec from sdk-config..."
curl -sSfL "$UPSTREAM_URL" -o "$TMP"

printf '# Source: https://github.com/OneBusAway/sdk-config/blob/main/openapi.yml\n# Fetched: %s\n' "$(date +%Y-%m-%d)" > "$DEST"
cat "$TMP" >> "$DEST"

echo "Updated $DEST"
Loading