Files
dokku/tests/unit/registry.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

521 lines
15 KiB
Bash

#!/usr/bin/env bats
load test_helper
setup() {
global_setup
create_app
dokku checks:set $TEST_APP wait-to-retire 30
}
teardown() {
destroy_app
global_teardown
}
@test "(registry) registry:help" {
run /bin/bash -c "dokku registry"
echo "output: $output"
echo "status: $status"
assert_output_contains "Manage registry settings for an app"
help_output="$output"
run /bin/bash -c "dokku registry:help"
echo "output: $output"
echo "status: $status"
assert_output_contains "Manage registry settings for an app"
assert_output "$help_output"
}
@test "(registry:login) global login with deprecated warning" {
if [[ -z "$DOCKERHUB_USERNAME" ]] || [[ -z "$DOCKERHUB_TOKEN" ]]; then
skip "skipping due to missing docker.io credentials DOCKERHUB_USERNAME:DOCKERHUB_TOKEN"
fi
run /bin/bash -c "dokku registry:login docker.io $DOCKERHUB_USERNAME $DOCKERHUB_TOKEN"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "Login Succeeded"
assert_output_contains "Deprecated: please use --global flag"
run /bin/bash -c "echo $DOCKERHUB_TOKEN | dokku registry:login docker.io --password-stdin $DOCKERHUB_USERNAME"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "Login Succeeded"
}
@test "(registry:login) global login with --global flag" {
if [[ -z "$DOCKERHUB_USERNAME" ]] || [[ -z "$DOCKERHUB_TOKEN" ]]; then
skip "skipping due to missing docker.io credentials DOCKERHUB_USERNAME:DOCKERHUB_TOKEN"
fi
run /bin/bash -c "dokku registry:login --global docker.io $DOCKERHUB_USERNAME $DOCKERHUB_TOKEN"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "Login Succeeded"
assert_output_not_contains "Deprecated"
}
@test "(registry:login) per-app login" {
if [[ -z "$DOCKERHUB_USERNAME" ]] || [[ -z "$DOCKERHUB_TOKEN" ]]; then
skip "skipping due to missing docker.io credentials DOCKERHUB_USERNAME:DOCKERHUB_TOKEN"
fi
run /bin/bash -c "dokku registry:login $TEST_APP docker.io $DOCKERHUB_USERNAME $DOCKERHUB_TOKEN"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "Login Succeeded"
run /bin/bash -c "test -f /var/lib/dokku/config/registry/$TEST_APP/config.json"
echo "output: $output"
echo "status: $status"
assert_success
}
@test "(registry:logout) per-app logout" {
if [[ -z "$DOCKERHUB_USERNAME" ]] || [[ -z "$DOCKERHUB_TOKEN" ]]; then
skip "skipping due to missing docker.io credentials DOCKERHUB_USERNAME:DOCKERHUB_TOKEN"
fi
run /bin/bash -c "dokku registry:login $TEST_APP docker.io $DOCKERHUB_USERNAME $DOCKERHUB_TOKEN"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku registry:logout $TEST_APP docker.io"
echo "output: $output"
echo "status: $status"
assert_success
}
@test "(registry:logout) global logout" {
if [[ -z "$DOCKERHUB_USERNAME" ]] || [[ -z "$DOCKERHUB_TOKEN" ]]; then
skip "skipping due to missing docker.io credentials DOCKERHUB_USERNAME:DOCKERHUB_TOKEN"
fi
run /bin/bash -c "dokku registry:login --global docker.io $DOCKERHUB_USERNAME $DOCKERHUB_TOKEN"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku registry:logout --global docker.io"
echo "output: $output"
echo "status: $status"
assert_success
}
@test "(registry) per-app credentials deleted on app destroy" {
if [[ -z "$DOCKERHUB_USERNAME" ]] || [[ -z "$DOCKERHUB_TOKEN" ]]; then
skip "skipping due to missing docker.io credentials DOCKERHUB_USERNAME:DOCKERHUB_TOKEN"
fi
run /bin/bash -c "dokku registry:login $TEST_APP docker.io $DOCKERHUB_USERNAME $DOCKERHUB_TOKEN"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "test -d /var/lib/dokku/config/registry/$TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
destroy_app
run /bin/bash -c "test -d /var/lib/dokku/config/registry/$TEST_APP"
echo "output: $output"
echo "status: $status"
assert_failure
create_app
}
@test "(registry:report) image-repo raw vs computed vs global" {
run /bin/bash -c "dokku registry:set --global image-repo-template"
assert_success
run /bin/bash -c "dokku registry:report $TEST_APP --format json | jq -r '.\"registry-image-repo\"'"
assert_success
assert_output ""
run /bin/bash -c "dokku registry:report $TEST_APP --format json | jq -r '.\"registry-global-image-repo-template\"'"
assert_success
assert_output ""
# When neither per-app image-repo nor a global image-repo-template are set,
# reportComputedImageRepo falls back to common.GetAppImageRepo which returns
# the default dokku/<app> image name.
run /bin/bash -c "dokku registry:report $TEST_APP --format json | jq -r '.\"registry-computed-image-repo\"'"
assert_success
assert_output "dokku/$TEST_APP"
run /bin/bash -c "dokku registry:set --global image-repo-template 'dokku/{{ APP }}'"
assert_success
run /bin/bash -c "dokku registry:report $TEST_APP --format json | jq -r '.\"registry-global-image-repo-template\"'"
assert_success
assert_output 'dokku/{{ APP }}'
run /bin/bash -c "dokku registry:report $TEST_APP --format json | jq -r '.\"registry-computed-image-repo\"'"
assert_success
assert_output "dokku/$TEST_APP"
run /bin/bash -c "dokku registry:set $TEST_APP image-repo my/$TEST_APP"
assert_success
run /bin/bash -c "dokku registry:report $TEST_APP --format json | jq -r '.\"registry-image-repo\"'"
assert_success
assert_output "my/$TEST_APP"
run /bin/bash -c "dokku registry:report $TEST_APP --format json | jq -r '.\"registry-computed-image-repo\"'"
assert_success
assert_output "my/$TEST_APP"
run /bin/bash -c "dokku registry:set $TEST_APP image-repo"
assert_success
run /bin/bash -c "dokku registry:set --global image-repo-template"
assert_success
}
@test "(registry:report) push-on-release raw vs computed vs global" {
run /bin/bash -c "dokku registry:set --global push-on-release"
assert_success
run /bin/bash -c "dokku registry:report $TEST_APP --format json | jq -r '.\"registry-push-on-release\"'"
assert_success
assert_output ""
run /bin/bash -c "dokku registry:report $TEST_APP --format json | jq -r '.\"registry-global-push-on-release\"'"
assert_success
assert_output ""
run /bin/bash -c "dokku registry:report $TEST_APP --format json | jq -r '.\"registry-computed-push-on-release\"'"
assert_success
assert_output "false"
run /bin/bash -c "dokku registry:set --global push-on-release true"
assert_success
run /bin/bash -c "dokku registry:report $TEST_APP --format json | jq -r '.\"registry-global-push-on-release\"'"
assert_success
assert_output "true"
run /bin/bash -c "dokku registry:report $TEST_APP --format json | jq -r '.\"registry-computed-push-on-release\"'"
assert_success
assert_output "true"
run /bin/bash -c "dokku registry:set $TEST_APP push-on-release false"
assert_success
run /bin/bash -c "dokku registry:report $TEST_APP --format json | jq -r '.\"registry-push-on-release\"'"
assert_success
assert_output "false"
run /bin/bash -c "dokku registry:report $TEST_APP --format json | jq -r '.\"registry-computed-push-on-release\"'"
assert_success
assert_output "false"
run /bin/bash -c "dokku registry:set $TEST_APP push-on-release"
assert_success
run /bin/bash -c "dokku registry:set --global push-on-release"
assert_success
}
@test "(registry:report) push-extra-tags raw" {
run /bin/bash -c "dokku registry:report $TEST_APP --format json | jq -r '.\"registry-push-extra-tags\"'"
assert_success
assert_output ""
run /bin/bash -c "dokku registry:set $TEST_APP push-extra-tags release,stable"
assert_success
run /bin/bash -c "dokku registry:report $TEST_APP --format json | jq -r '.\"registry-push-extra-tags\"'"
assert_success
assert_output "release,stable"
run /bin/bash -c "dokku registry:set $TEST_APP push-extra-tags"
assert_success
}
@test "(registry) registry:set server" {
run /bin/bash -c "dokku registry:set --global server ghcr.io"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku registry:report $TEST_APP --registry-server"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_not_exists
run /bin/bash -c "dokku registry:report $TEST_APP --registry-global-server"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "ghcr.io"
run /bin/bash -c "dokku registry:report $TEST_APP --registry-computed-server"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "ghcr.io/"
run /bin/bash -c "dokku registry:set --global server docker.io"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku registry:report $TEST_APP --registry-server"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_not_exists
run /bin/bash -c "dokku registry:report $TEST_APP --registry-global-server"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "docker.io"
run /bin/bash -c "dokku registry:report $TEST_APP --registry-computed-server"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_not_exists
run /bin/bash -c "dokku registry:set $TEST_APP server docker.io"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku registry:report $TEST_APP --registry-computed-server"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_not_exists
run /bin/bash -c "dokku registry:report $TEST_APP --registry-global-server"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "docker.io"
run /bin/bash -c "dokku registry:report $TEST_APP --registry-server"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "docker.io"
run /bin/bash -c "dokku registry:set $TEST_APP server ghcr.io"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku registry:report $TEST_APP --registry-computed-server"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "ghcr.io/"
run /bin/bash -c "dokku registry:report $TEST_APP --registry-global-server"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "docker.io"
run /bin/bash -c "dokku registry:report $TEST_APP --registry-server"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "ghcr.io"
}
@test "(registry) registry:set image-repo" {
run /bin/bash -c "docker images"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku registry:set $TEST_APP image-repo heroku/$TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
run deploy_app
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "docker inspect heroku/$TEST_APP:latest"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "docker images"
echo "output: $output"
echo "status: $status"
assert_success
}
@test "(registry) registry:set push-on-release" {
if [[ -z "$DOCKERHUB_USERNAME" ]] || [[ -z "$DOCKERHUB_TOKEN" ]]; then
skip "skipping due to missing docker.io credentials DOCKERHUB_USERNAME:DOCKERHUB_TOKEN"
fi
run /bin/bash -c "dokku registry:set $TEST_APP push-on-release true"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku registry:set $TEST_APP image-repo dokku/test-app"
echo "output: $output"
echo "status: $status"
assert_success
run deploy_app
echo "output: $output"
echo "status: $status"
assert_success
sleep 60
run /bin/bash -c "dokku ps:retire"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "docker container ls -a"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "docker image ls"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
sleep 60
run /bin/bash -c "dokku ps:retire"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "docker container ls -a"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "docker image ls"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku config:set $TEST_APP key=VALUE"
echo "output: $output"
echo "status: $status"
assert_success
sleep 60
run /bin/bash -c "dokku ps:retire"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "docker container ls -a"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "docker image ls"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
sleep 60
run /bin/bash -c "dokku ps:retire"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku ps:retire"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "docker container ls -a"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "docker image ls"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "docker image inspect dokku/test-app:1"
echo "output: $output"
echo "status: $status"
assert_failure
run /bin/bash -c "docker image inspect dokku/test-app:2"
echo "output: $output"
echo "status: $status"
assert_failure
run /bin/bash -c "docker image inspect dokku/test-app:3"
echo "output: $output"
echo "status: $status"
assert_failure
run /bin/bash -c "docker image inspect dokku/test-app:4"
echo "output: $output"
echo "status: $status"
assert_success
}
@test "(registry) registry:set push-extra-tags" {
if [[ -z "$DOCKERHUB_USERNAME" ]] || [[ -z "$DOCKERHUB_TOKEN" ]]; then
skip "skipping due to missing docker.io credentials DOCKERHUB_USERNAME:DOCKERHUB_TOKEN"
fi
run /bin/bash -c "dokku registry:set $TEST_APP push-on-release true"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku registry:set $TEST_APP image-repo dokku/test-app"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku registry:set $TEST_APP push-extra-tags foo"
echo "output: $output"
echo "status: $status"
assert_success
run deploy_app
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "dokku/test-app:foo"
}