Files
dokku/tests/unit/haproxy.bats
Jose Diaz-Gonzalez f8ccf52079 refactor: only use detected port mapping if override is not specified
Previously, we would always set the port mapping during a dockerfile build, making it difficult for users to override mappings. We also only _sometimes_ updated the detected port mapping, further confusing issues when users were migrating from Dockerfile to Buildpacks for builds.

Now, we always detect the port mapping during the build process, and only use that detected port mapping if an override is not specified. This greatly simplifies the experience around port mapping, as now a user can create an app, set a port mapping, and that first deploy will respect the port mapping without an additional deploy.

The builder always has the best context for what the app should be listening on, and thus we can always specify a "default" port mapping at this stage. Users can override this map as desired later.

This change also results in the removal of a ton of internal code that is now centralized in the ports plugin.

Closes #4067
2023-08-05 10:58:57 -04:00

167 lines
4.1 KiB
Bash

#!/usr/bin/env bats
load test_helper
setup() {
global_setup
dokku nginx:stop
dokku haproxy:set --global letsencrypt-server https://acme-staging-v02.api.letsencrypt.org/directory
dokku haproxy:set --global letsencrypt-email
dokku haproxy:start
create_app
}
teardown() {
global_teardown
destroy_app
dokku haproxy:stop
dokku nginx:start
}
@test "(haproxy) haproxy:help" {
run /bin/bash -c "dokku haproxy"
echo "output: $output"
echo "status: $status"
assert_output_contains "Manage the haproxy proxy integration"
help_output="$output"
run /bin/bash -c "dokku haproxy:help"
echo "output: $output"
echo "status: $status"
assert_output_contains "Manage the haproxy proxy integration"
assert_output "$help_output"
}
@test "(haproxy) log-level" {
run /bin/bash -c "dokku haproxy:set --global log-level DEBUG"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku haproxy:stop"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku haproxy:start"
echo "output: $output"
echo "status: $status"
assert_success
}
@test "(haproxy) single domain" {
run /bin/bash -c "dokku proxy:set $TEST_APP haproxy"
echo "output: $output"
echo "status: $status"
assert_success
run deploy_app python dokku@dokku.me:$TEST_APP convert_to_dockerfile
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "curl --silent $(dokku url $TEST_APP)"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "python/http.server"
}
@test "(haproxy) multiple domains" {
run /bin/bash -c "dokku proxy:set $TEST_APP haproxy"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku domains:add $TEST_APP $TEST_APP.dokku.me"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku domains:add $TEST_APP $TEST_APP-2.dokku.me"
echo "output: $output"
echo "status: $status"
assert_success
run deploy_app python dokku@dokku.me:$TEST_APP convert_to_dockerfile
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "curl --silent $TEST_APP.dokku.me"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "python/http.server"
run /bin/bash -c "curl --silent $TEST_APP-2.dokku.me"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "python/http.server"
}
@test "(haproxy) ssl" {
run /bin/bash -c "dokku builder-herokuish:set $TEST_APP allowed true"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku proxy:set $TEST_APP haproxy"
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 $TEST_APP.web.1 --format '{{ index .Config.Labels \"haproxy.$TEST_APP-web.redirect_ssl\" }}'"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "false"
run /bin/bash -c "dokku haproxy:set --global letsencrypt-email test@example.com"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku haproxy:stop"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku haproxy:start"
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
run /bin/bash -c "dokku ps:inspect $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"haproxy.$TEST_APP-web.redirect_ssl\" }}'"
echo "output: $output"
echo "status: $status"
assert_success
assert_output "true"
run /bin/bash -c "dokku --quiet ports:report $TEST_APP --ports-map"
echo "output: $output"
echo "status: $status"
assert_output_not_exists
run /bin/bash -c "dokku --quiet ports:report $TEST_APP --ports-map-detected"
echo "output: $output"
echo "status: $status"
assert_output "http:80:5000"
}