Files
dokku/tests/unit/proxy-route-caddy.bats
T
Jose Diaz-Gonzalez 40e13b5f13 fix: address PR review feedback on per-backend route tests
T1 of every per-backend test file asserted 200 with the api Procfile body for a request that lacks --strip-prefix, but without the strip the upstream sees /api/v0/Procfile and python's http.server returns 404; the retry loop polled on status only and accepted web's catch-all 200 first. The assertion now expects 404, which is the right signal that the route reaches the api process. T3 was rewritten to follow T2's two-step pattern (404 without strip, then 200 with strip) so the route is proven applied before checking content. T4 of proxy-route-nginx.bats relaxes the WebSocket header assertions to allow more than one occurrence because the headers correctly appear in both the route location block and the existing location / block. Backticks in fn-traefik-host-rule and fn-traefik-route-labels are now triple-escaped so they survive the docker-args eval path that turns the labels into a docker run invocation, matching the existing convention in docker-args-process-deploy. The label-based backend test files also echo the ps:rebuild output now so future failures of that step surface in the CI logs instead of silently exiting non-zero.
2026-11-04 14:56:38 -05:00

111 lines
3.6 KiB
Bash

#!/usr/bin/env bats
load test_helper
setup() {
global_setup
dokku nginx:stop
dokku caddy:start
create_app
dokku proxy:set "$TEST_APP" caddy
}
teardown() {
dokku proxy:route:clear "$TEST_APP" >/dev/null 2>&1 || true
destroy_app
dokku caddy:stop
dokku nginx:start
global_teardown
}
@test "(proxy-route:caddy) basic routing - /api/v0 hits api, / hits web" {
run deploy_app python "dokku@$DOKKU_DOMAIN:$TEST_APP" add_api_process_callback
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku ps:scale $TEST_APP web=1 api=1"
assert_success
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0 --port 5001"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
# Without --strip-prefix, /api/v0/Procfile reaches api as /api/v0/Procfile
# which python's http.server returns 404 for. A 404 here proves the route
# reaches api - web's catch-all would have returned 200.
assert_http_localhost_response_contains "http" "${TEST_APP}.${DOKKU_DOMAIN}" "80" "/api/v0/Procfile" "" "404"
}
@test "(proxy-route:caddy) --strip-prefix toggles upstream path visibility" {
run deploy_app python "dokku@$DOKKU_DOMAIN:$TEST_APP" add_api_process_callback
assert_success
run /bin/bash -c "dokku ps:scale $TEST_APP web=1 api=1"
assert_success
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0 --port 5001"
assert_success
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
assert_http_localhost_response_contains "http" "${TEST_APP}.${DOKKU_DOMAIN}" "80" "/api/v0/Procfile" "" "404"
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0 --port 5001 --strip-prefix"
assert_success
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
assert_http_localhost_response_contains "http" "${TEST_APP}.${DOKKU_DOMAIN}" "80" "/api/v0/Procfile" "python3 -m http.server"
}
@test "(proxy-route:caddy) removing a route falls back to web" {
run deploy_app python "dokku@$DOKKU_DOMAIN:$TEST_APP" add_api_process_callback
assert_success
run /bin/bash -c "dokku ps:scale $TEST_APP web=1 api=1"
assert_success
# Set without --strip-prefix first; 404 proves the labels attached.
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0 --port 5001"
assert_success
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
assert_http_localhost_response_contains "http" "${TEST_APP}.${DOKKU_DOMAIN}" "80" "/api/v0/Procfile" "" "404"
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0 --port 5001 --strip-prefix"
assert_success
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
assert_http_localhost_response_contains "http" "${TEST_APP}.${DOKKU_DOMAIN}" "80" "/api/v0/Procfile" "python3 -m http.server"
run /bin/bash -c "dokku proxy:route:remove $TEST_APP /api/v0"
assert_success
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
run curl --connect-to "${TEST_APP}.${DOKKU_DOMAIN}:80:localhost:80" -kSso /tmp/route-removed-body "http://${TEST_APP}.${DOKKU_DOMAIN}:80/api/v0/Procfile"
run /bin/bash -c "grep -c 'python3 -m http.server' /tmp/route-removed-body || true"
assert_output "0"
}
add_api_process_callback() {
local APP="$1"
local APP_REPO_DIR="$2"
echo "api: python3 -m http.server 5001" >>"$APP_REPO_DIR/Procfile"
}