Files
dokku/tests/unit/proxy-route.bats
T
Jose Diaz-Gonzalez 4a550fe4b9 feat: render proxy routes under openresty and add per-backend tests
Bumps the openresty sidecar to 0.12.0, which introduces the openresty.route.<n>.* label family for path-based routing. The openresty-vhosts plugin now emits route labels for non-web containers targeted by a proxy:route:set, mirroring the traefik and caddy patterns. Adds integration tests for every rendering backend (proxy-route-{nginx,traefik,caddy,openresty}.bats covering basic routing, --strip-prefix, and removal) plus per-ingress-class scheduler-k3s tests (proxy-route-k3s-{nginx,traefik}.bats covering the same three cases against a real cluster). The nginx file additionally asserts the rendered nginx config carries the WebSocket upgrade headers in each route's location block.
2026-11-04 14:56:38 -05:00

234 lines
6.8 KiB
Bash

#!/usr/bin/env bats
load test_helper
setup() {
global_setup
create_app
}
teardown() {
dokku proxy:route:clear "$TEST_APP" >/dev/null 2>&1 || true
destroy_app
global_teardown
}
@test "(proxy:route) help text mentions route commands" {
run /bin/bash -c "dokku proxy:help"
echo "output: $output"
echo "status: $status"
assert_output_contains "proxy:route:set"
assert_output_contains "proxy:route:remove"
assert_output_contains "proxy:route:clear"
assert_output_contains "proxy:route:report"
}
@test "(proxy:route:set) stores a route under the default port and is idempotent" {
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku proxy:route:report $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "/api/v0 -> api:5000"
# second call with identical args produces identical state
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku proxy:route:report $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_output_contains "/api/v0 -> api:5000"
}
@test "(proxy:route:set) --port overrides the default port" {
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 proxy:route:report $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_output_contains "/api/v0 -> api:5001"
}
@test "(proxy:route:set) --strip-prefix marks the route as stripping" {
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0 --strip-prefix"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku proxy:route:report $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_output_contains "/api/v0 -> api:5000 (strip)"
}
@test "(proxy:route:set) re-setting without --port resets port to default" {
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 proxy:route:set $TEST_APP api /api/v0"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku proxy:route:report $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_output_contains "/api/v0 -> api:5000"
}
@test "(proxy:route:set) re-setting without --strip-prefix resets strip to false" {
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0 --strip-prefix"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku proxy:route:report $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_output_not_contains "(strip)"
}
@test "(proxy:route:set) refuses web as a target" {
run /bin/bash -c "dokku proxy:route:set $TEST_APP web /api/v0"
echo "output: $output"
echo "status: $status"
assert_failure
assert_output_contains "web cannot be a route target"
}
@test "(proxy:route:set) refuses root path" {
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /"
echo "output: $output"
echo "status: $status"
assert_failure
assert_output_contains "reserved for the web process"
}
@test "(proxy:route:set) refuses path without leading slash" {
run /bin/bash -c "dokku proxy:route:set $TEST_APP api api/v0"
echo "output: $output"
echo "status: $status"
assert_failure
assert_output_contains "must start with /"
}
@test "(proxy:route:set) refuses path with trailing slash" {
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0/"
echo "output: $output"
echo "status: $status"
assert_failure
assert_output_contains "must not end with /"
}
@test "(proxy:route:set) refuses ports out of range" {
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0 --port 70000"
echo "output: $output"
echo "status: $status"
assert_failure
assert_output_contains "out of range"
}
@test "(proxy:route:set) warns when target process is scaled to zero" {
run /bin/bash -c "dokku ps:scale $TEST_APP api=0"
echo "output: $output"
echo "status: $status"
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "scaled to 0"
}
@test "(proxy:route:remove) deletes a route" {
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0"
assert_success
run /bin/bash -c "dokku proxy:route:remove $TEST_APP /api/v0"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku proxy:route:report $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_output_not_contains "/api/v0"
}
@test "(proxy:route:remove) is idempotent on a nonexistent path" {
run /bin/bash -c "dokku proxy:route:remove $TEST_APP /does/not/exist"
echo "output: $output"
echo "status: $status"
assert_success
}
@test "(proxy:route:clear) removes every route" {
dokku proxy:route:set "$TEST_APP" api /api/v0 >/dev/null
dokku proxy:route:set "$TEST_APP" api /api/v0/admin >/dev/null
dokku proxy:route:set "$TEST_APP" ws /ws --port 8080 >/dev/null
run /bin/bash -c "dokku proxy:route:clear $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku proxy:route:report $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_output_contains "(none)"
}
@test "(proxy:route:clear) is idempotent on an empty route set" {
run /bin/bash -c "dokku proxy:route:clear $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
}
@test "(proxy:route:report) supports json output" {
dokku proxy:route:set "$TEST_APP" api /api/v0 --port 5001 >/dev/null
dokku proxy:route:set "$TEST_APP" ws /ws --port 8080 --strip-prefix >/dev/null
run /bin/bash -c "dokku proxy:route:report $TEST_APP --format json | jq -e '.routes | length'"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "2"
run /bin/bash -c "dokku proxy:route:report $TEST_APP --format json | jq -r '.routes[] | select(.path == \"/ws\") | .strip_prefix'"
echo "output: $output"
echo "status: $status"
assert_output "true"
}
@test "(proxy:route:set) stores routes under haproxy backend even though they are inert" {
dokku proxy:set "$TEST_APP" haproxy >/dev/null 2>&1 || skip "haproxy proxy not available"
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku proxy:route:report $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_output_contains "/api/v0 -> api:5000"
}