diff --git a/tests/unit/10_apps.bats b/tests/unit/10_apps.bats index 621ad80b9..9558b3e9b 100644 --- a/tests/unit/10_apps.bats +++ b/tests/unit/10_apps.bats @@ -2,6 +2,14 @@ load test_helper +setup () { + global_setup +} + +teardown () { + global_teardown +} + @test "(apps) apps:create" { run dokku apps:create $TEST_APP echo "output: "$output diff --git a/tests/unit/10_certs.bats b/tests/unit/10_certs.bats index a827ad6c9..e7978ab13 100644 --- a/tests/unit/10_certs.bats +++ b/tests/unit/10_certs.bats @@ -15,6 +15,7 @@ teardown_local_tls() { } setup() { + global_setup create_app setup_local_tls } @@ -22,6 +23,7 @@ setup() { teardown() { destroy_app teardown_local_tls + global_teardown } @test "(certs) certs:add" { diff --git a/tests/unit/10_checks.bats b/tests/unit/10_checks.bats index 8fb37cca5..c0a8fafc5 100644 --- a/tests/unit/10_checks.bats +++ b/tests/unit/10_checks.bats @@ -7,11 +7,13 @@ load test_helper load test_helper setup() { + global_setup create_app } teardown() { destroy_app + global_teardown } @test "(checks) checks" { diff --git a/tests/unit/10_ps-dockerfile.bats b/tests/unit/10_ps-dockerfile.bats index 7627b7e75..15f1eea16 100644 --- a/tests/unit/10_ps-dockerfile.bats +++ b/tests/unit/10_ps-dockerfile.bats @@ -3,11 +3,13 @@ load test_helper setup() { + global_setup create_app } teardown() { destroy_app + global_teardown } # @test "(ps) dockerfile" { diff --git a/tests/unit/10_ps-general.bats b/tests/unit/10_ps-general.bats index 251882dc5..c18c6a746 100644 --- a/tests/unit/10_ps-general.bats +++ b/tests/unit/10_ps-general.bats @@ -3,11 +3,13 @@ load test_helper setup() { + global_setup create_app } teardown() { destroy_app + global_teardown } @test "(ps:scale) procfile commands extraction" { diff --git a/tests/unit/10_ps-herokuish.bats b/tests/unit/10_ps-herokuish.bats index 1e478c5d9..d3c00c001 100644 --- a/tests/unit/10_ps-herokuish.bats +++ b/tests/unit/10_ps-herokuish.bats @@ -3,12 +3,14 @@ load test_helper setup() { + global_setup create_app } teardown() { destroy_app destroy_app 0 "$MYAPP" || true + global_teardown } @test "(ps) herokuish" { diff --git a/tests/unit/10_repo.bats b/tests/unit/10_repo.bats index 86ef4888b..41b6fe066 100644 --- a/tests/unit/10_repo.bats +++ b/tests/unit/10_repo.bats @@ -3,11 +3,13 @@ load test_helper setup() { + global_setup deploy_app } teardown() { destroy_app + global_teardown } @test "(repo) repo:gc, repo:purge-cache" { diff --git a/tests/unit/10_tar.bats b/tests/unit/10_tar.bats index 64c23ff0b..f1dbaa141 100644 --- a/tests/unit/10_tar.bats +++ b/tests/unit/10_tar.bats @@ -3,11 +3,13 @@ load test_helper setup() { + global_setup create_app } teardown() { destroy_app + global_teardown } deploy_app_tar() { diff --git a/tests/unit/20_build-env.bats b/tests/unit/20_build-env.bats index eeecb5d36..c28413d1a 100644 --- a/tests/unit/20_build-env.bats +++ b/tests/unit/20_build-env.bats @@ -3,11 +3,13 @@ load test_helper setup() { + global_setup create_app } teardown() { destroy_app + global_teardown } @test "(build-env) special characters" { diff --git a/tests/unit/20_config.bats b/tests/unit/20_config.bats index 8d7634bde..a5894372c 100644 --- a/tests/unit/20_config.bats +++ b/tests/unit/20_config.bats @@ -3,6 +3,7 @@ load test_helper setup() { + global_setup [[ -f ${DOKKU_ROOT}/ENV ]] && mv -f ${DOKKU_ROOT}/ENV ${DOKKU_ROOT}/ENV.bak sudo -H -u dokku /bin/bash -c "echo 'export global_test=true' > ${DOKKU_ROOT}/ENV" create_app @@ -14,6 +15,7 @@ teardown() { if [[ -f ${DOKKU_ROOT}/ENV.bak ]];then mv -f ${DOKKU_ROOT}/ENV.bak ${DOKKU_ROOT}/ENV fi + global_teardown } @test "(config) config:set --global" { diff --git a/tests/unit/20_docker-options.bats b/tests/unit/20_docker-options.bats index da40a4ea0..7c9432f68 100644 --- a/tests/unit/20_docker-options.bats +++ b/tests/unit/20_docker-options.bats @@ -3,11 +3,13 @@ load test_helper setup() { + global_setup create_app } teardown() { destroy_app + global_teardown } @test "(docker-options) docker-options:add (all phases)" { diff --git a/tests/unit/20_domains.bats b/tests/unit/20_domains.bats index 173b36fc0..43c571d4e 100644 --- a/tests/unit/20_domains.bats +++ b/tests/unit/20_domains.bats @@ -3,6 +3,7 @@ load test_helper setup() { + global_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 @@ -12,6 +13,7 @@ teardown() { destroy_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" + global_teardown } @test "(domains) domains" { diff --git a/tests/unit/20_nginx-vhosts_1.bats b/tests/unit/20_nginx-vhosts_1.bats index 65d1b959d..17c576ed2 100644 --- a/tests/unit/20_nginx-vhosts_1.bats +++ b/tests/unit/20_nginx-vhosts_1.bats @@ -4,6 +4,7 @@ load test_helper source "$PLUGIN_CORE_AVAILABLE_PATH/config/functions" setup() { + global_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" } @@ -12,6 +13,7 @@ teardown() { destroy_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" + global_teardown } @test "(nginx-vhosts) nginx:build-config (domains:disable/enable)" { diff --git a/tests/unit/20_storage.bats b/tests/unit/20_storage.bats index a2b0059c7..befe2589e 100644 --- a/tests/unit/20_storage.bats +++ b/tests/unit/20_storage.bats @@ -3,11 +3,13 @@ load test_helper setup() { + global_setup create_app } teardown() { destroy_app + global_teardown } @test "(storage) storage:mount, storage:list, storage:umount" { diff --git a/tests/unit/30_client.bats b/tests/unit/30_client.bats index c62f1b6a8..7f1d97f00 100644 --- a/tests/unit/30_client.bats +++ b/tests/unit/30_client.bats @@ -3,6 +3,7 @@ load test_helper setup() { + global_setup export DOKKU_HOST=dokku.me create_app } @@ -10,6 +11,7 @@ setup() { teardown() { destroy_app unset DOKKU_HOST + global_teardown } @test "(client) unconfigured DOKKU_HOST" { diff --git a/tests/unit/30_core_1.bats b/tests/unit/30_core_1.bats index bb0fa6f44..310a2854c 100644 --- a/tests/unit/30_core_1.bats +++ b/tests/unit/30_core_1.bats @@ -3,6 +3,7 @@ load test_helper setup() { + global_setup create_app DOCKERFILE="$BATS_TMPDIR/Dockerfile" } @@ -12,6 +13,7 @@ teardown() { destroy_app dokku config:unset --global DOKKU_RM_CONTAINER rm -f "$DOCKERFILE" + global_teardown } assert_urls() { diff --git a/tests/unit/30_events.bats b/tests/unit/30_events.bats index e54e38339..8136e15a5 100644 --- a/tests/unit/30_events.bats +++ b/tests/unit/30_events.bats @@ -3,11 +3,13 @@ load test_helper setup() { + global_setup create_app } teardown() { destroy_app + global_teardown } @test "(events) check conffiles" { diff --git a/tests/unit/30_ssh_keys.bats b/tests/unit/30_ssh_keys.bats index 7bd43907e..d3f157c04 100644 --- a/tests/unit/30_ssh_keys.bats +++ b/tests/unit/30_ssh_keys.bats @@ -3,11 +3,13 @@ load test_helper setup() { + global_setup create_key } teardown() { destroy_key + global_teardown } @test "(ssh-keys) ssh-keys:add, ssh-keys:list, ssh-keys:remove" { diff --git a/tests/unit/40_core_2.bats b/tests/unit/40_core_2.bats index b3d860243..03bbee8ec 100644 --- a/tests/unit/40_core_2.bats +++ b/tests/unit/40_core_2.bats @@ -3,12 +3,14 @@ load test_helper setup() { + global_setup create_app } teardown() { rm -rf /home/dokku/$TEST_APP/tls destroy_app + global_teardown } assert_urls() { diff --git a/tests/unit/40_nginx-vhosts_2.bats b/tests/unit/40_nginx-vhosts_2.bats index 35d86651c..3932bdff1 100644 --- a/tests/unit/40_nginx-vhosts_2.bats +++ b/tests/unit/40_nginx-vhosts_2.bats @@ -4,6 +4,7 @@ load test_helper source "$PLUGIN_CORE_AVAILABLE_PATH/config/functions" setup() { + global_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 @@ -13,6 +14,7 @@ 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" + global_teardown } assert_access_log() { diff --git a/tests/unit/40_plugin.bats b/tests/unit/40_plugin.bats index d811116b2..9f90aaf76 100644 --- a/tests/unit/40_plugin.bats +++ b/tests/unit/40_plugin.bats @@ -4,12 +4,17 @@ load test_helper TEST_PLUGIN_NAME=smoke-test-plugin TEST_PLUGIN_GIT_REPO=https://github.com/dokku/${TEST_PLUGIN_NAME}.git +setup() { + global_setup +} + remove_test_plugin() { rm -rf $PLUGIN_ENABLED_PATH/$TEST_PLUGIN_NAME $PLUGIN_AVAILABLE_PATH/$TEST_PLUGIN_NAME } teardown() { remove_test_plugin || true + global_teardown } @test "(plugin) plugin:install, plugin:disable, plugin:update plugin:uninstall" { diff --git a/tests/unit/40_proxy.bats b/tests/unit/40_proxy.bats index d7e4cad43..329da8f33 100644 --- a/tests/unit/40_proxy.bats +++ b/tests/unit/40_proxy.bats @@ -3,6 +3,7 @@ load test_helper setup() { + global_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 @@ -12,6 +13,7 @@ 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" + global_teardown } assert_nonssl_domain() { diff --git a/tests/unit/40_tags.bats b/tests/unit/40_tags.bats index 02d154506..dc6b1568f 100644 --- a/tests/unit/40_tags.bats +++ b/tests/unit/40_tags.bats @@ -3,11 +3,13 @@ load test_helper setup() { + global_setup deploy_app } teardown() { destroy_app + global_teardown } @test "(tags) tags:create, tags, tags:destroy" { diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash index 4a4e188f6..e6d16da86 100644 --- a/tests/unit/test_helper.bash +++ b/tests/unit/test_helper.bash @@ -11,6 +11,17 @@ PLUGIN_CORE_AVAILABLE_PATH=${PLUGIN_CORE_AVAILABLE_PATH:="$PLUGIN_CORE_PATH/avai CUSTOM_TEMPLATE_SSL_DOMAIN=customssltemplate.dokku.me UUID=$(tr -dc 'a-z0-9' < /dev/urandom | fold -w 32 | head -n 1) TEST_APP="rdmtestapp-${UUID}" +SKIPPED_TEST_ERR_MSG="previous test failed! skipping remaining tests..." + +# global setup() and teardown() +# skips remaining tests on first failure +global_setup() { + [[ ! -f "${BATS_PARENT_TMPNAME}.skip" ]] || skip "$SKIPPED_TEST_ERR_MSG" +} + +global_teardown() { + [[ -n "$BATS_TEST_COMPLETED" ]] || touch "${BATS_PARENT_TMPNAME}.skip" +} # test functions flunk() {