Files
dokku/tests/unit/ps-general-3.bats
T
Jose Diaz-Gonzalez db45f8608b feat: add --clear and --replace flags to ps:scale
The `ps:scale` command merges the specified process types into the existing formation, so replacing an entire formation from the CLI required reading the current scale, diffing it, and issuing a second call to zero out each unlisted process type. The `--replace` flag treats the specified process types as the whole formation and sets the process count for every unspecified process type to zero, while the `--clear` flag resets the formation to the scale a newly created app has. The two flags cannot be combined, `--replace` requires at least one process type, and `--clear` accepts none. Process types cleared this way are now scaled down as part of the same command rather than being left running with a stale formation.
2026-09-02 14:55:16 -04:00

95 lines
2.4 KiB
Bash

#!/usr/bin/env bats
load test_helper
setup() {
global_setup
create_app
}
teardown() {
destroy_app
global_teardown
}
@test "(ps:scale) --replace scales down unspecified processes" {
run /bin/bash -c "dokku builder-herokuish:set $TEST_APP allowed true"
echo "output: $output"
echo "status: $status"
assert_success
run deploy_app python
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku ps:scale $TEST_APP worker=1"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "docker ps --filter label=com.dokku.app-name=$TEST_APP --filter label=com.dokku.process-type=worker --format '{{.Names}}' | wc -l"
output=$(echo "$output" | tr -d " ")
echo "output: ($output)"
echo "status: $status"
assert_output "1"
run /bin/bash -c "dokku ps:scale --replace $TEST_APP web=1"
echo "output: $output"
echo "status: $status"
assert_success
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\ntask: 0\nweb: 1\nworker: 0'
sleep 2
run /bin/bash -c "dokku ps:retire"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "docker ps --filter label=com.dokku.app-name=$TEST_APP --filter label=com.dokku.process-type=worker --format '{{.Names}}' | wc -l"
output=$(echo "$output" | tr -d " ")
echo "output: ($output)"
echo "status: $status"
assert_output "0"
}
@test "(ps:scale) --clear without a web process type" {
run /bin/bash -c "dokku ps:scale $TEST_APP web=0 console=0"
echo "output: $output"
echo "status: $status"
assert_success
run deploy_app python-console-only
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku ps:scale --skip-deploy $TEST_APP console=2"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku --quiet ps:scale $TEST_APP"
output=$(echo "$output" | tr -s " ")
echo "output: ($output)"
echo "status: $status"
assert_output "console: 2"
run /bin/bash -c "dokku ps:scale --clear $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku --quiet ps:scale $TEST_APP"
output=$(echo "$output" | tr -s " ")
echo "output: ($output)"
echo "status: $status"
assert_output "console: 0"
}