Removes the per-step docker inspect label dumps in the caddy/traefik/openresty backend tests, the kubectl get service/ingress/endpoints dumps in the k3s T1 tests, the openresty T2 sidecar log fallback that became unnecessary once 0.12.1 fixed the upstream cache regression, and the trailing cat of /tmp/route-removed-body in every T3. The output/status echoes that match the project's bats convention stay, as does the file-based grep in T3 and every assertion-bearing kubectl call.
164 lines
5.6 KiB
Bash
164 lines
5.6 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
load test_helper
|
|
|
|
TEST_APP="rdmtestapp"
|
|
|
|
setup() {
|
|
uninstall_k3s || true
|
|
global_setup
|
|
dokku nginx:stop
|
|
export KUBECONFIG="/etc/rancher/k3s/k3s.yaml"
|
|
}
|
|
|
|
teardown() {
|
|
global_teardown
|
|
dokku nginx:start
|
|
uninstall_k3s || true
|
|
}
|
|
|
|
@test "(proxy-route:k3s-traefik) basic routing - /api/v0 hits api, / hits web" {
|
|
if [[ -z "$DOCKERHUB_USERNAME" ]] || [[ -z "$DOCKERHUB_TOKEN" ]]; then
|
|
skip "skipping due to missing docker.io credentials DOCKERHUB_USERNAME:DOCKERHUB_TOKEN"
|
|
fi
|
|
|
|
INGRESS_CLASS=traefik install_k3s
|
|
|
|
run /bin/bash -c "dokku apps:create $TEST_APP"
|
|
assert_success
|
|
|
|
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
|
|
|
|
# scheduler-k3s does not yet have a proxy-build-config trigger handler, so
|
|
# proxy:route:set does not re-render the chart. ps:rebuild forces a redeploy
|
|
# which renders the chart with current routes. Runtime gap tracked as a
|
|
# follow-up; the test fix unblocks CI.
|
|
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. 404 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:k3s-traefik) --strip-prefix renders stripPrefix Middleware and strips upstream path" {
|
|
if [[ -z "$DOCKERHUB_USERNAME" ]] || [[ -z "$DOCKERHUB_TOKEN" ]]; then
|
|
skip "skipping due to missing docker.io credentials DOCKERHUB_USERNAME:DOCKERHUB_TOKEN"
|
|
fi
|
|
|
|
INGRESS_CLASS=traefik install_k3s
|
|
|
|
run /bin/bash -c "dokku apps:create $TEST_APP"
|
|
assert_success
|
|
|
|
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 first; the 404 proves the route reached api before we
|
|
# assert the strip-prefix HTTP behavior. ps:rebuild after each mutation
|
|
# forces a chart re-render (k3s has no proxy-build-config trigger yet).
|
|
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"
|
|
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"
|
|
assert_success
|
|
|
|
# The chart should emit a StripPrefix Middleware CRD when --strip-prefix
|
|
# is set.
|
|
run /bin/bash -c "kubectl get middleware.traefik.io -o json | jq -r '.items[].spec.stripPrefix.prefixes[]?' | head -1"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
assert_output_contains "/api/v0"
|
|
|
|
assert_http_localhost_response_contains "http" "${TEST_APP}.${DOKKU_DOMAIN}" "80" "/api/v0/Procfile" "python3 -m http.server"
|
|
}
|
|
|
|
@test "(proxy-route:k3s-traefik) removing a route drops the stripPrefix Middleware" {
|
|
if [[ -z "$DOCKERHUB_USERNAME" ]] || [[ -z "$DOCKERHUB_TOKEN" ]]; then
|
|
skip "skipping due to missing docker.io credentials DOCKERHUB_USERNAME:DOCKERHUB_TOKEN"
|
|
fi
|
|
|
|
INGRESS_CLASS=traefik install_k3s
|
|
|
|
run /bin/bash -c "dokku apps:create $TEST_APP"
|
|
assert_success
|
|
|
|
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
|
|
|
|
# Verify the route reaches api first (404 proves routing) before checking
|
|
# that strip applied (200 with Procfile content). ps:rebuild after each
|
|
# mutation forces a chart re-render (k3s has no proxy-build-config yet).
|
|
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"
|
|
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"
|
|
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"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
|
|
assert_success
|
|
|
|
# Confirm storage was cleared before checking cluster state.
|
|
run /bin/bash -c "dokku proxy:route:report $TEST_APP"
|
|
echo "output: $output"
|
|
echo "status: $status"
|
|
assert_success
|
|
assert_output_contains "(none)"
|
|
|
|
# The stripPrefix Middleware should be gone after removal. Retry briefly
|
|
# in case the chart re-render hasn't settled.
|
|
local count="1"
|
|
for attempt in $(seq 1 30); do
|
|
run /bin/bash -c "kubectl get middleware.traefik.io -o json | jq -r '[.items[] | select(.spec.stripPrefix != null)] | length'"
|
|
count="$output"
|
|
if [[ "$count" == "0" ]]; then
|
|
break
|
|
fi
|
|
sleep 1
|
|
done
|
|
echo "final middleware count after $attempt attempts: $count"
|
|
assert_equal "$count" "0"
|
|
}
|
|
|
|
add_api_process_callback() {
|
|
local APP="$1"
|
|
local APP_REPO_DIR="$2"
|
|
echo "api: python3 -m http.server 5001" >>"$APP_REPO_DIR/Procfile"
|
|
}
|