diff --git a/plugins/builder-nixpacks/builder-build b/plugins/builder-nixpacks/builder-build index df8662b55..8509c2a29 100755 --- a/plugins/builder-nixpacks/builder-build +++ b/plugins/builder-nixpacks/builder-build @@ -6,7 +6,6 @@ set -eo pipefail [[ $DOKKU_TRACE ]] && set -x trigger-builder-nixpacks-builder-build() { - set -x declare desc="builder-nixpacks builder-build plugin trigger" declare trigger="builder-build" declare BUILDER_TYPE="$1" APP="$2" SOURCECODE_WORK_DIR="$3" @@ -257,7 +256,6 @@ trigger-builder-nixpacks-builder-build() { plugn trigger post-build "$BUILDER_TYPE" "$APP" "$SOURCECODE_WORK_DIR" popd &>/dev/null || pushd "/tmp" >/dev/null - set +x } trigger-builder-nixpacks-builder-build "$@" diff --git a/tests/apps/python/Procfile b/tests/apps/python/Procfile index 77b9a38ff..8a57141ee 100644 --- a/tests/apps/python/Procfile +++ b/tests/apps/python/Procfile @@ -8,6 +8,7 @@ web: python3 -u web.py first.Procfile # testing inline comment worker: python3 -u worker.py custom: echo -n release: python3 -u release.py +task: python3 -u task.py test # Old version with separate processes (use this if you have issues with the threaded version) diff --git a/tests/unit/builder-dockerfile.bats b/tests/unit/builder-dockerfile.bats index 754a09be1..73c5b9c99 100644 --- a/tests/unit/builder-dockerfile.bats +++ b/tests/unit/builder-dockerfile.bats @@ -147,15 +147,22 @@ EOF echo "status: $status" assert_success - run deploy_app dockerfile + run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP convert_to_dockerfile echo "output: $output" echo "status: $status" assert_success - run /bin/bash -c "dokku ps:inspect $TEST_APP" + run /bin/bash -c "dokku run $TEST_APP python3 task.py test" echo "output: $output" echo "status: $status" assert_success + assert_output "['task.py', 'test']" + + run /bin/bash -c "dokku --quiet run $TEST_APP task" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "['task.py', 'test']" run /bin/bash -c "dokku run $TEST_APP env" echo "output: $output" diff --git a/tests/unit/builder-herokuish.bats b/tests/unit/builder-herokuish.bats index 8677d52e5..fb1536f91 100644 --- a/tests/unit/builder-herokuish.bats +++ b/tests/unit/builder-herokuish.bats @@ -105,10 +105,17 @@ teardown() { echo "status: $status" assert_success - run /bin/bash -c "dokku ps:inspect $TEST_APP" + run /bin/bash -c "dokku run $TEST_APP python3 task.py test" echo "output: $output" echo "status: $status" assert_success + assert_output "['task.py', 'test']" + + run /bin/bash -c "dokku --quiet run $TEST_APP task" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "['task.py', 'test']" run /bin/bash -c "dokku run $TEST_APP env" echo "output: $output" diff --git a/tests/unit/builder-nixpacks.bats b/tests/unit/builder-nixpacks.bats index 98a9734b5..e66a6147a 100644 --- a/tests/unit/builder-nixpacks.bats +++ b/tests/unit/builder-nixpacks.bats @@ -29,7 +29,7 @@ teardown() { echo "output: $output" echo "status: $status" assert_success - assert_output_contains 'load build definition from Dockerfile' + assert_output_contains 'load build definition from Dockerfile' -1 assert_output_contains "SECRET_KEY: fjdkslafjdk" run /bin/bash -c "dokku builder-nixpacks:set $TEST_APP nixpackstoml-path nonexistent.toml" @@ -41,7 +41,7 @@ teardown() { echo "output: $output" echo "status: $status" assert_success - assert_output_contains 'load build definition from Dockerfile' + assert_output_contains 'load build definition from Dockerfile' -1 } @test "(builder-nixpacks) run" { @@ -59,11 +59,20 @@ teardown() { echo "output: $output" echo "status: $status" assert_success + assert_output_contains 'load build definition from Dockerfile' -1 + assert_output_contains "SECRET_KEY: fjdkslafjdk" - run /bin/bash -c "dokku ps:inspect $TEST_APP" + run /bin/bash -c "dokku run $TEST_APP python3 task.py test" echo "output: $output" echo "status: $status" assert_success + assert_output "['task.py', 'test']" + + run /bin/bash -c "dokku --quiet run $TEST_APP task" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "['task.py', 'test']" run /bin/bash -c "dokku run $TEST_APP env" echo "output: $output" diff --git a/tests/unit/builder-pack.bats b/tests/unit/builder-pack.bats index 3ad4eaf1a..55c662149 100644 --- a/tests/unit/builder-pack.bats +++ b/tests/unit/builder-pack.bats @@ -95,16 +95,17 @@ teardown() { assert_output_contains 'Building with buildpack 1' 0 assert_output_contains 'Installing dependencies using pip' - run /bin/bash -c "dokku run $TEST_APP python task.py test" + run /bin/bash -c "dokku run $TEST_APP python3 task.py test" echo "output: $output" echo "status: $status" assert_success assert_output "['task.py', 'test']" - run /bin/bash -c "dokku ps:inspect $TEST_APP" + run /bin/bash -c "dokku --quiet run $TEST_APP task" echo "output: $output" echo "status: $status" assert_success + assert_output "['task.py', 'test']" run /bin/bash -c "dokku run $TEST_APP env" echo "output: $output" diff --git a/tests/unit/builder-railpack.bats b/tests/unit/builder-railpack.bats index e0dcc5f6c..a904e553b 100644 --- a/tests/unit/builder-railpack.bats +++ b/tests/unit/builder-railpack.bats @@ -5,7 +5,6 @@ load test_helper setup_file() { global_setup install_railpack - docker run --rm --privileged -d --name buildkit moby/buildkit:latest touch /etc/default/dokku sudo tee -a /etc/default/dokku <<<"export BUILDKIT_HOST='docker-container://buildkit'" } @@ -16,7 +15,9 @@ teardown_file() { } setup() { + global_setup create_app + docker run --rm --privileged -d --name buildkit moby/buildkit:latest } teardown() { @@ -54,6 +55,43 @@ teardown() { assert_output_contains 'Successfully built image in' } +@test "(builder-pack) run" { + run /bin/bash -c "dokku config:set $TEST_APP SECRET_KEY=fjdkslafjdk" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku builder:set $TEST_APP selected railpack" + echo "output: $output" + echo "status: $status" + assert_success + + run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP inject_requirements_txt + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains 'create mise config' + assert_output_contains 'Successfully built image in' + + run /bin/bash -c "dokku run $TEST_APP python3 task.py test" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "['task.py', 'test']" + + run /bin/bash -c "dokku --quiet run $TEST_APP task" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "['task.py', 'test']" + + run /bin/bash -c "dokku run $TEST_APP env" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains "SECRET_KEY=fjdkslafjdk" +} + inject_requirements_txt() { local APP="$1" local APP_REPO_DIR="$2" diff --git a/tests/unit/ps-general-2.bats b/tests/unit/ps-general-2.bats index 379d7727d..db2520b3b 100644 --- a/tests/unit/ps-general-2.bats +++ b/tests/unit/ps-general-2.bats @@ -169,7 +169,7 @@ teardown() { run /bin/bash -c "dokku --quiet ps:scale $TEST_APP" output=$(echo "$output" | tr -s " ") echo "output: ($output)" - assert_output $'cron: 0\ncustom: 0\nrelease: 0\nweb: 1\nworker: 1' + assert_output $'cron: 0\ncustom: 0\nrelease: 0\ntask: 0\nweb: 1\nworker: 1' run /bin/bash -c "dokku ps:scale $TEST_APP worker=0" echo "output: $output" @@ -179,7 +179,7 @@ teardown() { run /bin/bash -c "dokku --quiet ps:scale $TEST_APP" output=$(echo "$output" | tr -s " ") echo "output: ($output)" - assert_output $'cron: 0\ncustom: 0\nrelease: 0\nweb: 1\nworker: 0' + assert_output $'cron: 0\ncustom: 0\nrelease: 0\ntask: 0\nweb: 1\nworker: 0' run /bin/bash -c "dokku ps:set $TEST_APP procfile-path second.Procfile" echo "output: $output" diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash index 1669d5c29..95e89376d 100644 --- a/tests/unit/test_helper.bash +++ b/tests/unit/test_helper.bash @@ -148,6 +148,14 @@ assert_output_contains() { input="${input/$expected/}" found=$((found + 1)) done + + if [[ "$count" -eq -1 ]]; then + if [[ "$found" -gt 0 ]]; then + return 0 + fi + flunk "expected at least 1 occurrence of '$expected', found $found" + fi + [[ "$count" -eq "$found" ]] || flunk "expected $count occurrences of '$expected', found $found" }