Files
dokku/tests/unit/nginx-vhosts_properties.bats
T
Jose Diaz-Gonzalez 357e12bd83 refactor: rename computed-* helpers, expose computed vector and network keys
Addresses review feedback on #8640. fn-archive-max-size,
fn-archive-max-files, fn-git-deploy-branch, and fn-git-keep-git-dir are
renamed with `computed` in the function name so the names match the
resolved-with-default semantic they implement, and every caller is
updated in lockstep. logs:report renames the misordered
--logs-vector-global-image and --logs-vector-global-networks to
--logs-global-vector-image and --logs-global-vector-networks, makes the
global getters return the raw stored value, and adds
--logs-computed-vector-image, --logs-computed-vector-networks, and
--logs-computed-vector-sink. network:report --global gains the
computed-* keys for attach-post-create, attach-post-deploy,
initial-network, and tld so external tooling can read the resolved
value at global scope. The --quiet flag is dropped from every
:report --format json | jq invocation across the PR's bats files; the
report's --format json output is the only stdout and the flag is
redundant.
2026-05-23 04:47:03 -04:00

104 lines
3.9 KiB
Bash

#!/usr/bin/env bats
load test_helper
setup() {
global_setup
create_app
}
teardown() {
destroy_app
global_teardown
}
# assert_nginx_property_set_get verifies that for a given nginx property,
# (a) the raw per-app and global keys cycle through set/unset states,
# (b) the computed key always returns a non-empty value when defaults exist,
# and (c) the computed key falls back through per-app -> global.
#
# This intentionally does not pin the exact default value for properties whose
# default is computed at runtime (e.g. proxy-buffer-size depends on the host's
# page size) - those would be brittle to assert verbatim. The set/unset cycle
# is the canonical test for the report convention.
assert_nginx_property_set_get() {
declare prop="$1" app_value="$2" global_value="$3"
run /bin/bash -c "dokku nginx:set --global $prop"
assert_success
run /bin/bash -c "dokku nginx:set --global $prop '$global_value'"
assert_success
run /bin/bash -c "dokku nginx:report $TEST_APP --format json | jq -r '.\"global-$prop\"'"
assert_success
assert_output "$global_value"
run /bin/bash -c "dokku nginx:report $TEST_APP --format json | jq -r '.\"computed-$prop\"'"
assert_success
assert_output "$global_value"
run /bin/bash -c "dokku nginx:set $TEST_APP $prop '$app_value'"
assert_success
run /bin/bash -c "dokku nginx:report $TEST_APP --format json | jq -r '.\"$prop\"'"
assert_success
assert_output "$app_value"
run /bin/bash -c "dokku nginx:report $TEST_APP --format json | jq -r '.\"global-$prop\"'"
assert_success
assert_output "$global_value"
run /bin/bash -c "dokku nginx:report $TEST_APP --format json | jq -r '.\"computed-$prop\"'"
assert_success
assert_output "$app_value"
run /bin/bash -c "dokku nginx:set $TEST_APP $prop"
assert_success
run /bin/bash -c "dokku nginx:set --global $prop"
assert_success
}
@test "(nginx:report) timeout properties raw/global/computed" {
for prop in client-body-timeout client-header-timeout keepalive-timeout lingering-timeout send-timeout proxy-connect-timeout proxy-read-timeout proxy-send-timeout; do
assert_nginx_property_set_get "$prop" "30s" "45s"
done
}
@test "(nginx:report) buffer properties raw/global/computed" {
assert_nginx_property_set_get "proxy-buffer-size" "8k" "16k"
assert_nginx_property_set_get "proxy-buffering" "off" "on"
assert_nginx_property_set_get "proxy-buffers" "16 16k" "32 16k"
assert_nginx_property_set_get "proxy-busy-buffers-size" "16k" "32k"
assert_nginx_property_set_get "client-max-body-size" "10m" "20m"
}
@test "(nginx:report) hsts properties raw/global/computed" {
assert_nginx_property_set_get "hsts" "false" "true"
assert_nginx_property_set_get "hsts-include-subdomains" "false" "true"
assert_nginx_property_set_get "hsts-max-age" "3600" "7200"
assert_nginx_property_set_get "hsts-preload" "true" "false"
}
@test "(nginx:report) x-forwarded properties raw/global/computed" {
assert_nginx_property_set_get "x-forwarded-for-value" "\$remote_addr" "\$proxy_add_x_forwarded_for"
assert_nginx_property_set_get "x-forwarded-port-value" "8080" "8443"
assert_nginx_property_set_get "x-forwarded-proto-value" "https" "http"
assert_nginx_property_set_get "x-forwarded-ssl" "on" "off"
}
@test "(nginx:report) log/address properties raw/global/computed" {
assert_nginx_property_set_get "bind-address-ipv4" "127.0.0.1" "0.0.0.0"
assert_nginx_property_set_get "bind-address-ipv6" "::1" "::"
assert_nginx_property_set_get "access-log-format" "main" "combined"
assert_nginx_property_set_get "access-log-path" "/var/log/nginx/app-access.log" "/dev/stdout"
assert_nginx_property_set_get "error-log-path" "/var/log/nginx/app-error.log" "/dev/stderr"
}
@test "(nginx:report) misc properties raw/global/computed" {
assert_nginx_property_set_get "disable-custom-config" "false" "true"
assert_nginx_property_set_get "underscore-in-headers" "on" "off"
assert_nginx_property_set_get "proxy-keepalive" "8" "16"
}