Files
dokku/tests/unit/ps-general-1.bats
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

277 lines
7.7 KiB
Bash

#!/usr/bin/env bats
load test_helper
setup() {
global_setup
create_app
}
teardown() {
destroy_app
global_teardown
}
@test "(ps) ps:help" {
run /bin/bash -c "dokku ps"
echo "output: $output"
echo "status: $status"
assert_output_contains "Manage app processes"
help_output="$output"
run /bin/bash -c "dokku ps:help"
echo "output: $output"
echo "status: $status"
assert_output_contains "Manage app processes"
assert_output "$help_output"
}
@test "(ps) ps:inspect" {
run /bin/bash -c "dokku config:set $TEST_APP key=value key=value=value"
echo "output: $output"
echo "status: $status"
assert_success
run deploy_app dockerfile
echo "output: $output"
echo "status: $status"
assert_success
CID=$(<$DOKKU_ROOT/$TEST_APP/CONTAINER.web.1)
run /bin/bash -c "dokku ps:inspect $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "$CID" 7
}
@test "(ps:set) procfile" {
run /bin/bash -c "dokku ps:set --global procfile-path .dokku/Procfile"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku ps:report $TEST_APP --ps-computed-procfile-path"
echo "output: $output"
echo "status: $status"
assert_output ".dokku/Procfile"
assert_success
run /bin/bash -c "dokku ps:report $TEST_APP --ps-global-procfile-path"
echo "output: $output"
echo "status: $status"
assert_output ".dokku/Procfile"
assert_success
run /bin/bash -c "dokku ps:report $TEST_APP --ps-procfile-path"
echo "output: $output"
echo "status: $status"
assert_output ""
assert_success
run /bin/bash -c "dokku ps:set --global procfile-path"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku ps:report $TEST_APP --ps-computed-procfile-path"
echo "output: $output"
echo "status: $status"
assert_output "Procfile"
assert_success
run /bin/bash -c "dokku ps:report $TEST_APP --ps-global-procfile-path"
echo "output: $output"
echo "status: $status"
assert_output ""
assert_success
run /bin/bash -c "dokku ps:report $TEST_APP --ps-procfile-path"
echo "output: $output"
echo "status: $status"
assert_output ""
assert_success
}
@test "(ps:scale) procfile commands extraction" {
source "$PLUGIN_CORE_AVAILABLE_PATH/ps/functions"
cat <<EOF >"$DOKKU_LIB_ROOT/data/ps/$TEST_APP/Procfile"
web: node web.js --port \$PORT
worker: node worker.js
release: interpolated \$ENV_VAR
EOF
run /bin/bash -c "dokku config:set '$TEST_APP' ENV_VAR=value"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku plugin:trigger procfile-get-command '$TEST_APP' web 5001"
echo "output: $output"
echo "status: $status"
assert_output "node web.js --port 5001"
run /bin/bash -c "dokku plugin:trigger procfile-get-command '$TEST_APP' worker"
echo "output: $output"
echo "status: $status"
assert_output "node worker.js"
run /bin/bash -c "dokku plugin:trigger procfile-get-command '$TEST_APP' release 5001"
echo "output: $output"
echo "status: $status"
assert_output "interpolated value"
}
@test "(ps:scale) update formations from Procfile" {
local TMP=$(mktemp -d "/tmp/${DOKKU_DOMAIN}.XXXXX")
trap 'popd &>/dev/null || true; rm -rf "$TMP"' INT TERM
CUSTOM_TMP="$TMP" deploy_app nodejs-express
run /bin/bash -c "dokku --quiet ps:scale $TEST_APP"
output=$(echo "$output" | tr -s " ")
echo "output: ($output)"
echo "status: $status"
assert_output $'cron: 0\ncustom: 0\nrelease: 0\nweb: 1\nworker: 0'
pushd $TMP
echo scaletest: sleep infinity >>Procfile
git commit Procfile -m 'Add scaletest process'
git push target master:master
run /bin/bash -c "dokku --quiet ps:scale $TEST_APP"
output=$(echo "$output" | tr -s " ")
echo "output: ($output)"
echo "status: $status"
assert_output $'cron: 0\ncustom: 0\nrelease: 0\nscaletest: 0\nweb: 1\nworker: 0'
popd
rm -rf "$TMP"
}
@test "(ps:scale) ps:scale formatting" {
echo "web=4
worker=1
beat =0
web =0" >/var/lib/dokku/config/ps/$TEST_APP/scale
run /bin/bash -c "dokku --quiet ps:scale $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_output $'beat: 0\nweb: 4\nworker: 1'
}
@test "(ps) handle windows newlines in procfile" {
run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP procfile_line_endings_to_windows
echo "output: $output"
echo "status: $status"
assert_success
}
@test "(ps:report) stop-timeout-seconds raw vs computed vs global" {
run /bin/bash -c "dokku ps:set --global stop-timeout-seconds"
assert_success
run /bin/bash -c "dokku ps:report $TEST_APP --format json | jq -r '.\"stop-timeout-seconds\"'"
assert_success
assert_output ""
run /bin/bash -c "dokku ps:report $TEST_APP --format json | jq -r '.\"global-stop-timeout-seconds\"'"
assert_success
assert_output ""
run /bin/bash -c "dokku ps:report $TEST_APP --format json | jq -r '.\"computed-stop-timeout-seconds\"'"
assert_success
assert_output "30"
run /bin/bash -c "dokku ps:set --global stop-timeout-seconds 90"
assert_success
run /bin/bash -c "dokku ps:report $TEST_APP --format json | jq -r '.\"global-stop-timeout-seconds\"'"
assert_success
assert_output "90"
run /bin/bash -c "dokku ps:report $TEST_APP --format json | jq -r '.\"computed-stop-timeout-seconds\"'"
assert_success
assert_output "90"
run /bin/bash -c "dokku ps:set $TEST_APP stop-timeout-seconds 45"
assert_success
run /bin/bash -c "dokku ps:report $TEST_APP --format json | jq -r '.\"stop-timeout-seconds\"'"
assert_success
assert_output "45"
run /bin/bash -c "dokku ps:report $TEST_APP --format json | jq -r '.\"global-stop-timeout-seconds\"'"
assert_success
assert_output "90"
run /bin/bash -c "dokku ps:report $TEST_APP --format json | jq -r '.\"computed-stop-timeout-seconds\"'"
assert_success
assert_output "45"
run /bin/bash -c "dokku ps:set $TEST_APP stop-timeout-seconds"
assert_success
run /bin/bash -c "dokku ps:set --global stop-timeout-seconds"
assert_success
}
@test "(ps:restart-policy) default policy" {
run /bin/bash -c "dokku ps:report $TEST_APP --ps-restart-policy"
echo "output: $output"
echo "status: $status"
assert_output "on-failure:10"
}
@test "(ps:restart-policy) ps:set restart-policy" {
for policy in no unless-stopped always on-failure on-failure:20; do
run /bin/bash -c "dokku ps:set $TEST_APP restart-policy $policy"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku ps:report $TEST_APP --ps-restart-policy"
echo "output: $output"
echo "status: $status"
assert_output "$policy"
done
}
@test "(ps:restart-policy) deployed policy" {
test_restart_policy="on-failure:20"
run /bin/bash -c "dokku ps:set $TEST_APP restart-policy $test_restart_policy"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku ps:report $TEST_APP --ps-restart-policy"
echo "output: $output"
echo "status: $status"
assert_output "$test_restart_policy"
run deploy_app dockerfile
echo "output: $output"
echo "status: $status"
assert_success
CID=$(<$DOKKU_ROOT/$TEST_APP/CONTAINER.web.1)
run /bin/bash -c "docker inspect $CID"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "docker inspect -f '{{ .HostConfig.RestartPolicy.Name }}:{{ .HostConfig.RestartPolicy.MaximumRetryCount }}' $CID"
echo "output: $output"
echo "status: $status"
assert_output "$test_restart_policy"
}
procfile_line_endings_to_windows() {
local APP="$1"
local APP_REPO_DIR="$2"
[[ -z "$APP" ]] && local APP="$TEST_APP"
echo "setting line endings on Procfile to \n via unix2dos"
sed -i -e 's/\r*$/\r/' "$APP_REPO_DIR/Procfile"
}