feat: port vhost proxy :report subcommands to golang
The bash :report implementations for the caddy, haproxy, openresty, and traefik proxy plugins are replaced with a compiled golang binary that collects report keys in parallel and marshals json directly. The traefik dns-provider values keep their masking behaviour, remaining hidden in the default stdout report while surfacing for --format json or an explicit flag query. These four plugins previously had no unit tests, so a bats suite covering the report matrix is added for each.
This commit is contained in:
84
tests/unit/caddy-vhosts.bats
Normal file
84
tests/unit/caddy-vhosts.bats
Normal file
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
create_app
|
||||
}
|
||||
|
||||
teardown() {
|
||||
destroy_app
|
||||
dokku caddy:set --global log-level >/dev/null 2>&1 || true
|
||||
dokku caddy:set --global tls-internal >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
@test "(caddy:report) info-flag works before deploy" {
|
||||
run /bin/bash -c "dokku caddy:report $TEST_APP --caddy-computed-tls-internal"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "false"
|
||||
|
||||
run /bin/bash -c "dokku caddy:report $TEST_APP --caddy-invalid-flag"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_failure
|
||||
assert_output_contains "Invalid flag passed"
|
||||
}
|
||||
|
||||
@test "(caddy:report) --format json" {
|
||||
run /bin/bash -c "dokku caddy:set --global log-level"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku caddy:report --global --format json | jq -e ."
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku caddy:report --global --format json | jq -r '.\"computed-log-level\"'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "ERROR"
|
||||
|
||||
run /bin/bash -c "dokku caddy:report --global"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains "global caddy information"
|
||||
}
|
||||
|
||||
@test "(caddy:report) tls-internal raw global computed" {
|
||||
run /bin/bash -c "dokku caddy:set --global tls-internal"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku caddy:report $TEST_APP --caddy-tls-internal"
|
||||
assert_success
|
||||
assert_output ""
|
||||
|
||||
run /bin/bash -c "dokku caddy:report $TEST_APP --caddy-computed-tls-internal"
|
||||
assert_success
|
||||
assert_output "false"
|
||||
|
||||
run /bin/bash -c "dokku caddy:set --global tls-internal true"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku caddy:report $TEST_APP --caddy-global-tls-internal"
|
||||
assert_success
|
||||
assert_output "true"
|
||||
|
||||
run /bin/bash -c "dokku caddy:report $TEST_APP --caddy-computed-tls-internal"
|
||||
assert_success
|
||||
assert_output "true"
|
||||
|
||||
run /bin/bash -c "dokku caddy:set $TEST_APP tls-internal false"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku caddy:report $TEST_APP --caddy-tls-internal"
|
||||
assert_success
|
||||
assert_output "false"
|
||||
|
||||
run /bin/bash -c "dokku caddy:report $TEST_APP --caddy-computed-tls-internal"
|
||||
assert_success
|
||||
assert_output "false"
|
||||
}
|
||||
76
tests/unit/haproxy-vhosts.bats
Normal file
76
tests/unit/haproxy-vhosts.bats
Normal file
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
create_app
|
||||
}
|
||||
|
||||
teardown() {
|
||||
destroy_app
|
||||
dokku haproxy:set --global log-level >/dev/null 2>&1 || true
|
||||
dokku haproxy:set --global refresh-conf >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
@test "(haproxy:report) info-flag works before deploy" {
|
||||
run /bin/bash -c "dokku haproxy:set --global refresh-conf"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku haproxy:report $TEST_APP --haproxy-computed-refresh-conf"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "10"
|
||||
|
||||
run /bin/bash -c "dokku haproxy:report $TEST_APP --haproxy-invalid-flag"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_failure
|
||||
assert_output_contains "Invalid flag passed"
|
||||
}
|
||||
|
||||
@test "(haproxy:report) --format json" {
|
||||
run /bin/bash -c "dokku haproxy:set --global log-level"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku haproxy:report --global --format json | jq -e ."
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku haproxy:report --global --format json | jq -r '.\"computed-log-level\"'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "ERROR"
|
||||
|
||||
run /bin/bash -c "dokku haproxy:report --global"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains "global haproxy information"
|
||||
}
|
||||
|
||||
@test "(haproxy:report) refresh-conf global computed" {
|
||||
run /bin/bash -c "dokku haproxy:set --global refresh-conf"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku haproxy:report --global --haproxy-global-refresh-conf"
|
||||
assert_success
|
||||
assert_output ""
|
||||
|
||||
run /bin/bash -c "dokku haproxy:report --global --haproxy-computed-refresh-conf"
|
||||
assert_success
|
||||
assert_output "10"
|
||||
|
||||
run /bin/bash -c "dokku haproxy:set --global refresh-conf 30"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku haproxy:report --global --haproxy-global-refresh-conf"
|
||||
assert_success
|
||||
assert_output "30"
|
||||
|
||||
run /bin/bash -c "dokku haproxy:report --global --haproxy-computed-refresh-conf"
|
||||
assert_success
|
||||
assert_output "30"
|
||||
}
|
||||
84
tests/unit/openresty-vhosts.bats
Normal file
84
tests/unit/openresty-vhosts.bats
Normal file
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
create_app
|
||||
}
|
||||
|
||||
teardown() {
|
||||
destroy_app
|
||||
dokku openresty:set --global log-level >/dev/null 2>&1 || true
|
||||
dokku openresty:set --global proxy-buffer-size >/dev/null 2>&1 || true
|
||||
dokku openresty:set --global client-max-body-size >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
@test "(openresty:report) info-flag works before deploy" {
|
||||
run /bin/bash -c "dokku openresty:set --global log-level"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku openresty:report $TEST_APP --openresty-computed-log-level"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "ERROR"
|
||||
|
||||
run /bin/bash -c "dokku openresty:report $TEST_APP --openresty-invalid-flag"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_failure
|
||||
assert_output_contains "Invalid flag passed"
|
||||
}
|
||||
|
||||
@test "(openresty:report) --format json" {
|
||||
run /bin/bash -c "dokku openresty:set --global proxy-buffer-size"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku openresty:report --global --format json | jq -e ."
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku openresty:report --global --format json | jq -r '.\"computed-proxy-buffer-size\"'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "4k"
|
||||
|
||||
run /bin/bash -c "dokku openresty:report --global"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains "global openresty information"
|
||||
}
|
||||
|
||||
@test "(openresty:report) client-max-body-size raw global computed" {
|
||||
run /bin/bash -c "dokku openresty:set --global client-max-body-size"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku openresty:report $TEST_APP --openresty-client-max-body-size"
|
||||
assert_success
|
||||
assert_output ""
|
||||
|
||||
run /bin/bash -c "dokku openresty:report $TEST_APP --openresty-computed-client-max-body-size"
|
||||
assert_success
|
||||
assert_output "1m"
|
||||
|
||||
run /bin/bash -c "dokku openresty:set --global client-max-body-size 2m"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku openresty:report $TEST_APP --openresty-computed-client-max-body-size"
|
||||
assert_success
|
||||
assert_output "2m"
|
||||
|
||||
run /bin/bash -c "dokku openresty:set $TEST_APP client-max-body-size 5m"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku openresty:report $TEST_APP --openresty-client-max-body-size"
|
||||
assert_success
|
||||
assert_output "5m"
|
||||
|
||||
run /bin/bash -c "dokku openresty:report $TEST_APP --openresty-computed-client-max-body-size"
|
||||
assert_success
|
||||
assert_output "5m"
|
||||
}
|
||||
72
tests/unit/traefik-vhosts.bats
Normal file
72
tests/unit/traefik-vhosts.bats
Normal file
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
create_app
|
||||
}
|
||||
|
||||
teardown() {
|
||||
destroy_app
|
||||
dokku traefik:set --global challenge-mode >/dev/null 2>&1 || true
|
||||
dokku traefik:set --global dns-provider-test_key >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
@test "(traefik:report) info-flag works before deploy" {
|
||||
run /bin/bash -c "dokku traefik:set --global challenge-mode"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku traefik:report $TEST_APP --traefik-computed-challenge-mode"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "tls"
|
||||
|
||||
run /bin/bash -c "dokku traefik:report $TEST_APP --traefik-invalid-flag"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_failure
|
||||
assert_output_contains "Invalid flag passed"
|
||||
}
|
||||
|
||||
@test "(traefik:report) --format json" {
|
||||
run /bin/bash -c "dokku traefik:report --global --format json | jq -e ."
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku traefik:report --global --format json | jq -r '.\"computed-api-enabled\"'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "false"
|
||||
|
||||
run /bin/bash -c "dokku traefik:report --global"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains "global traefik information"
|
||||
}
|
||||
|
||||
@test "(traefik:report) dns-provider values are masked unless queried" {
|
||||
run /bin/bash -c "dokku traefik:set --global dns-provider-test_key secretvalue"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku traefik:report --global | grep test_key"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains "*******"
|
||||
|
||||
run /bin/bash -c "dokku traefik:report --global --traefik-dns-provider-test_key"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "secretvalue"
|
||||
|
||||
run /bin/bash -c "dokku traefik:report --global --format json | jq -r '.\"dns-provider-test_key\"'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "secretvalue"
|
||||
}
|
||||
Reference in New Issue
Block a user