Files
dokku/tests/unit/40_proxy.bats
Jose Diaz-Gonzalez bd7deae883 Add ability to remove a specific port mapping tuple
This allows users to specify port 80 after an application has had domain added. Normally, when we first add an extra domain, the following tuple is added:

    http:80:5000

A user might then want to remap port 80 to another port, such as port 8080:

    dokku proxy:ports-add APP http:80:8080

The application would then have the following proxy map:

    http:80:5000 http:80:8080

As nginx vhosts are resolved in FIFO order, the "correct" upstream of 8080 would basically be ignored. The workaround would be to remove the original port mapping, but the following:

    dokku proxy:ports-remove APP 80

Would remove *both* entries and then re-add the default of `http:80:5000`. Thus it was not possible to use the porcelain to correct the port mapping and a user would have to fall back to using the following hack to fix their mapping:

    dokku config:set APP DOKKU_PROXY_PORT_MAP='http:80:8080'

You can now use the previous syntax *as well as* the following to remove a port mapping:

    dokku proxy:ports-remove APP http:80:5000
2016-06-20 23:17:55 -04:00

122 lines
3.3 KiB
Bash

#!/usr/bin/env bats
load test_helper
setup() {
[[ -f "$DOKKU_ROOT/VHOST" ]] && cp -fp "$DOKKU_ROOT/VHOST" "$DOKKU_ROOT/VHOST.bak"
[[ -f "$DOKKU_ROOT/HOSTNAME" ]] && cp -fp "$DOKKU_ROOT/HOSTNAME" "$DOKKU_ROOT/HOSTNAME.bak"
create_app
}
teardown() {
destroy_app 0 $TEST_APP
[[ -f "$DOKKU_ROOT/VHOST.bak" ]] && mv "$DOKKU_ROOT/VHOST.bak" "$DOKKU_ROOT/VHOST" && chown dokku:dokku "$DOKKU_ROOT/VHOST"
[[ -f "$DOKKU_ROOT/HOSTNAME.bak" ]] && mv "$DOKKU_ROOT/HOSTNAME.bak" "$DOKKU_ROOT/HOSTNAME" && chown dokku:dokku "$DOKKU_ROOT/HOSTNAME"
}
assert_nonssl_domain() {
local domain=$1
assert_app_domain "${domain}"
assert_http_success "http://${domain}"
}
assert_app_domain() {
local domain=$1
run /bin/bash -c "dokku domains $TEST_APP | grep -xF ${domain}"
echo "output: "$output
echo "status: "$status
assert_output "${domain}"
}
assert_external_port() {
local CID="$1"; local exit_status="$2"
local EXTERNAL_PORT_COUNT=$(docker port $CID | wc -l)
run /bin/bash -c "[[ $EXTERNAL_PORT_COUNT -gt 0 ]]"
if [[ "$exit_status" == "success" ]]; then
assert_success
else
assert_failure
fi
}
@test "(proxy) proxy:enable/disable" {
deploy_app
assert_nonssl_domain "${TEST_APP}.dokku.me"
run dokku proxy:disable $TEST_APP
echo "output: "$output
echo "status: "$status
assert_success
for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.web.*; do
assert_external_port $(< $CID_FILE) success
done
run dokku proxy:enable $TEST_APP
echo "output: "$output
echo "status: "$status
assert_success
assert_http_success "${TEST_APP}.dokku.me"
for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.web.*; do
assert_external_port $(< $CID_FILE) failure
done
}
@test "(proxy) proxy:ports (list/add/remove/clear)" {
run dokku proxy:ports-add $TEST_APP http:8080:5000 https:8443:5000 http:1234:5001
echo "output: "$output
echo "status: "$status
assert_success
run /bin/bash -c "dokku --quiet proxy:ports $TEST_APP | xargs"
echo "output: "$output
echo "status: "$status
assert_output "http 1234 5001 http 8080 5000 https 8443 5000"
run /bin/bash -c "dokku proxy:ports-remove $TEST_APP 8080"
echo "output: "$output
echo "status: "$status
assert_success
run /bin/bash -c "dokku --quiet proxy:ports $TEST_APP | xargs"
echo "output: "$output
echo "status: "$status
assert_output "http 1234 5001 https 8443 5000"
run /bin/bash -c "dokku proxy:ports-remove $TEST_APP http:1234:5001"
echo "output: "$output
echo "status: "$status
assert_success
run /bin/bash -c "dokku --quiet proxy:ports $TEST_APP | xargs"
echo "output: "$output
echo "status: "$status
assert_output "https 8443 5000"
run /bin/bash -c "dokku proxy:ports-clear $TEST_APP"
echo "output: "$output
echo "status: "$status
assert_success
run /bin/bash -c "dokku --quiet proxy:ports $TEST_APP | xargs"
echo "output: "$output
echo "status: "$status
assert_output "http 80 5000"
}
@test "(proxy) proxy:ports (post-deploy add)" {
deploy_app
run dokku proxy:ports-add $TEST_APP http:8080:5000 http:8081:5000
echo "output: "$output
echo "status: "$status
assert_success
URLS="$(dokku --quiet urls "$TEST_APP")"
for URL in $URLS; do
assert_http_success $URL
done
assert_http_success "http://$TEST_APP.dokku.me:8080"
assert_http_success "http://$TEST_APP.dokku.me:8081"
}