From c9caa0880fbfe95885c837fc4f670499e5e5e1a6 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 18 Aug 2022 11:13:34 -0400 Subject: [PATCH] tests: add unit tests and support multiple routers/services in traefik --- .../traefik-vhosts/docker-args-process-deploy | 2 + tests/unit/traefik.bats | 83 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 tests/unit/traefik.bats diff --git a/plugins/traefik-vhosts/docker-args-process-deploy b/plugins/traefik-vhosts/docker-args-process-deploy index 93572ead1..9b46c9af8 100755 --- a/plugins/traefik-vhosts/docker-args-process-deploy +++ b/plugins/traefik-vhosts/docker-args-process-deploy @@ -91,6 +91,7 @@ trigger-traefik-vhosts-docker-args-process-deploy() { output="$output --label traefik.http.services.$APP-$PROC_TYPE.loadbalancer.server.port=$proxy_container_http_port" output="$output --label traefik.http.routers.$APP-$PROC_TYPE.entrypoints=http" + output="$output --label traefik.http.routers.$APP-$PROC_TYPE.service=$APP-$PROC_TYPE" if [[ -n "$traefik_domains" ]]; then output="$output --label \"traefik.http.routers.$APP-$PROC_TYPE.rule=Host(\\\`$traefik_domains\\\`)\"" echo "# THIS FILE IS GENERATED BY DOKKU - DO NOT EDIT, YOUR CHANGES WILL BE OVERWRITTEN" >"$app_urls_path" @@ -107,6 +108,7 @@ trigger-traefik-vhosts-docker-args-process-deploy() { output="$output --label traefik.http.services.$APP-$PROC_TYPE-https.loadbalancer.server.port=$proxy_container_https_port" output="$output --label traefik.http.routers.$APP-$PROC_TYPE-https.entrypoints=https" + output="$output --label traefik.http.routers.$APP-$PROC_TYPE-https.service=$APP-$PROC_TYPE-https" if [[ -n "$traefik_domains" ]]; then output="$output --label \"traefik.http.routers.$APP-$PROC_TYPE-https.rule=Host(\\\`$traefik_domains\\\`)\"" echo "# THIS FILE IS GENERATED BY DOKKU - DO NOT EDIT, YOUR CHANGES WILL BE OVERWRITTEN" >"$app_urls_path" diff --git a/tests/unit/traefik.bats b/tests/unit/traefik.bats new file mode 100644 index 000000000..a37624afb --- /dev/null +++ b/tests/unit/traefik.bats @@ -0,0 +1,83 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + global_setup + dokku nginx:stop + dokku traefik:start + create_app +} + +teardown() { + global_teardown + destroy_app + dokku traefik:stop + dokku nginx:start +} + +@test "(traefik) traefik:help" { + run /bin/bash -c "dokku traefik" + echo "output: $output" + echo "status: $status" + assert_output_contains "Manage the traefik proxy integration" + help_output="$output" + + run /bin/bash -c "dokku traefik:help" + echo "output: $output" + echo "status: $status" + assert_output_contains "Manage the traefik proxy integration" + assert_output "$help_output" +} + +@test "(traefik) single domain" { + run /bin/bash -c "dokku proxy:set $TEST_APP traefik" + echo "output: $output" + echo "status: $status" + assert_success + + run deploy_app + 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 "(traefik) multiple domains" { + run /bin/bash -c "dokku proxy:set $TEST_APP traefik" + 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 + 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" +}