From b1ebd694e6fa056fa51193c13597a57a9e4aa495 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 4 Jan 2026 00:35:30 -0500 Subject: [PATCH 1/6] refactor: standardize on add_requirements_txt wrapper --- tests/unit/builder-nixpacks.bats | 11 ++--------- tests/unit/builder-railpack.bats | 11 ++--------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/tests/unit/builder-nixpacks.bats b/tests/unit/builder-nixpacks.bats index e66a6147a..72ba86a21 100644 --- a/tests/unit/builder-nixpacks.bats +++ b/tests/unit/builder-nixpacks.bats @@ -25,7 +25,7 @@ teardown() { echo "status: $status" assert_success - run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP inject_requirements_txt + run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP add_requirements_txt echo "output: $output" echo "status: $status" assert_success @@ -55,7 +55,7 @@ teardown() { echo "status: $status" assert_success - run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP inject_requirements_txt + run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP add_requirements_txt echo "output: $output" echo "status: $status" assert_success @@ -80,10 +80,3 @@ teardown() { assert_success assert_output_contains "SECRET_KEY=fjdkslafjdk" } - -inject_requirements_txt() { - local APP="$1" - local APP_REPO_DIR="$2" - [[ -z "$APP" ]] && local APP="$TEST_APP" - echo "flask" >>"$APP_REPO_DIR/requirements.txt" -} diff --git a/tests/unit/builder-railpack.bats b/tests/unit/builder-railpack.bats index a904e553b..260062443 100644 --- a/tests/unit/builder-railpack.bats +++ b/tests/unit/builder-railpack.bats @@ -36,7 +36,7 @@ teardown() { echo "status: $status" assert_success - run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP inject_requirements_txt + run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP add_requirements_txt echo "output: $output" echo "status: $status" assert_success @@ -66,7 +66,7 @@ teardown() { echo "status: $status" assert_success - run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP inject_requirements_txt + run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP add_requirements_txt echo "output: $output" echo "status: $status" assert_success @@ -91,10 +91,3 @@ teardown() { assert_success assert_output_contains "SECRET_KEY=fjdkslafjdk" } - -inject_requirements_txt() { - local APP="$1" - local APP_REPO_DIR="$2" - [[ -z "$APP" ]] && local APP="$TEST_APP" - echo "flask" >>"$APP_REPO_DIR/requirements.txt" -} From c19cb81c4bed34908d443a5247f0d4558f436e2d Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 4 Jan 2026 00:39:06 -0500 Subject: [PATCH 2/6] tests: add a test to prove cron:run commands work as expected Closes #8242 --- tests/apps/python/app-cnb-cron.json | 29 ++++++++++++++++++++ tests/apps/python/app-cnb.json | 2 +- tests/apps/python/app-cron.json | 29 ++++++++++++++++++++ tests/unit/builder-dockerfile.bats | 39 +++++++++++++++++++++++++++ tests/unit/builder-herokuish.bats | 38 ++++++++++++++++++++++++++ tests/unit/builder-nixpacks.bats | 41 ++++++++++++++++++++++++++++ tests/unit/builder-pack.bats | 42 +++++++++++++++++++++++++++++ tests/unit/builder-railpack.bats | 41 ++++++++++++++++++++++++++++ 8 files changed, 260 insertions(+), 1 deletion(-) create mode 100644 tests/apps/python/app-cnb-cron.json create mode 100644 tests/apps/python/app-cron.json diff --git a/tests/apps/python/app-cnb-cron.json b/tests/apps/python/app-cnb-cron.json new file mode 100644 index 000000000..54d9aa7a1 --- /dev/null +++ b/tests/apps/python/app-cnb-cron.json @@ -0,0 +1,29 @@ +{ + "cron": [ + { + "command": "python3 task.py some cron task", + "schedule": "5 5 5 5 5" + } + ], + "healthchecks": { + "web": [ + { + "attempts": 2, + "content": "python/http.server", + "name": "check-1", + "path": "/", + "timeout": 5, + "type": "startup", + "wait": 2 + } + ] + }, + "scripts": { + "dokku": { + // this is a comment for the postdeploy script + "postdeploy": "touch /workspace/postdeploy.test", + // this is a comment for the predeploy script + "predeploy": "touch /workspace/predeploy.test" + } + } +} diff --git a/tests/apps/python/app-cnb.json b/tests/apps/python/app-cnb.json index 85f5fe7f0..0d7012432 100644 --- a/tests/apps/python/app-cnb.json +++ b/tests/apps/python/app-cnb.json @@ -18,4 +18,4 @@ "predeploy": "touch /workspace/predeploy.test" } } -} \ No newline at end of file +} diff --git a/tests/apps/python/app-cron.json b/tests/apps/python/app-cron.json new file mode 100644 index 000000000..89f2543ce --- /dev/null +++ b/tests/apps/python/app-cron.json @@ -0,0 +1,29 @@ +{ + "cron": [ + { + "command": "python3 task.py some cron task", + "schedule": "5 5 5 5 5" + } + ], + "healthchecks": { + "web": [ + { + "attempts": 2, + "content": "python/http.server", + "name": "check-1", + "path": "/", + "timeout": 5, + "type": "startup", + "wait": 2 + } + ] + }, + "scripts": { + "dokku": { + // this is a comment for the postdeploy script + "postdeploy": "touch /app/postdeploy.test", + // this is a comment for the predeploy script + "predeploy": "touch /app/predeploy.test" + } + } +} \ No newline at end of file diff --git a/tests/unit/builder-dockerfile.bats b/tests/unit/builder-dockerfile.bats index 73c5b9c99..d61e6379f 100644 --- a/tests/unit/builder-dockerfile.bats +++ b/tests/unit/builder-dockerfile.bats @@ -170,3 +170,42 @@ EOF assert_success assert_output_contains "SECRET_KEY=fjdkslafjdk" } + +@test "(builder-dockerfile) cron: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 dockerfile" + echo "output: $output" + echo "status: $status" + assert_success + + run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP cron_run_wrapper + echo "output: $output" + echo "status: $status" + assert_success + + cron_id="$(dokku cron:list $TEST_APP --format json | jq -r '.[0].id')" + run /bin/bash -c "echo $cron_id" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_exists + + run /bin/bash -c "dokku cron:run $TEST_APP $cron_id" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "['task.py', 'some', 'cron', 'task']" +} + +cron_run_wrapper() { + local APP="$1" + local APP_REPO_DIR="$2" + [[ -z "$APP" ]] && local APP="$TEST_APP" + + convert_to_dockerfile "$APP" "$APP_REPO_DIR" + mv -f "$APP_REPO_DIR/app-cron.json" "$APP_REPO_DIR/app.json" +} diff --git a/tests/unit/builder-herokuish.bats b/tests/unit/builder-herokuish.bats index fb1536f91..f794e3ca2 100644 --- a/tests/unit/builder-herokuish.bats +++ b/tests/unit/builder-herokuish.bats @@ -123,3 +123,41 @@ teardown() { assert_success assert_output_contains "SECRET_KEY=fjdkslafjdk" } + +@test "(builder-herokuish) cron: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 herokuish" + echo "output: $output" + echo "status: $status" + assert_success + + run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP cron_run_wrapper + echo "output: $output" + echo "status: $status" + assert_success + + cron_id="$(dokku cron:list $TEST_APP --format json | jq -r '.[0].id')" + run /bin/bash -c "echo $cron_id" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_exists + + run /bin/bash -c "dokku cron:run $TEST_APP $cron_id" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "['task.py', 'some', 'cron', 'task']" +} + +cron_run_wrapper() { + local APP="$1" + local APP_REPO_DIR="$2" + [[ -z "$APP" ]] && local APP="$TEST_APP" + + mv -f "$APP_REPO_DIR/app-cron.json" "$APP_REPO_DIR/app.json" +} diff --git a/tests/unit/builder-nixpacks.bats b/tests/unit/builder-nixpacks.bats index 72ba86a21..a7fd3ac6e 100644 --- a/tests/unit/builder-nixpacks.bats +++ b/tests/unit/builder-nixpacks.bats @@ -80,3 +80,44 @@ teardown() { assert_success assert_output_contains "SECRET_KEY=fjdkslafjdk" } + +@test "(builder-nixpacks) cron: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 nixpacks" + echo "output: $output" + echo "status: $status" + assert_success + + run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP cron_run_wrapper + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains 'load build definition from Dockerfile' -1 + assert_output_contains "SECRET_KEY: fjdkslafjdk" + + cron_id="$(dokku cron:list $TEST_APP --format json | jq -r '.[0].id')" + run /bin/bash -c "echo $cron_id" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_exists + + run /bin/bash -c "dokku cron:run $TEST_APP $cron_id" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "['task.py', 'some', 'cron', 'task']" +} + +cron_run_wrapper() { + local APP="$1" + local APP_REPO_DIR="$2" + [[ -z "$APP" ]] && local APP="$TEST_APP" + + add_requirements_txt "$APP" "$APP_REPO_DIR" + mv -f "$APP_REPO_DIR/app-cron.json" "$APP_REPO_DIR/app.json" +} diff --git a/tests/unit/builder-pack.bats b/tests/unit/builder-pack.bats index 55c662149..d8081f48e 100644 --- a/tests/unit/builder-pack.bats +++ b/tests/unit/builder-pack.bats @@ -143,3 +143,45 @@ teardown() { assert_success assert_output_contains '"APP_RESPECTS_ENV_VARS": "1"' } + +@test "(builder-pack) cron: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 pack" + echo "output: $output" + echo "status: $status" + assert_success + + run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP cron_run_wrapper + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains 'from cnb stack' + assert_output_contains 'Building with buildpack 1' 0 + assert_output_contains 'Installing dependencies using pip' + + cron_id="$(dokku cron:list $TEST_APP --format json | jq -r '.[0].id')" + run /bin/bash -c "echo $cron_id" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_exists + + run /bin/bash -c "dokku cron:run $TEST_APP $cron_id" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "['task.py', 'some', 'cron', 'task']" +} + +cron_run_wrapper() { + local APP="$1" + local APP_REPO_DIR="$2" + [[ -z "$APP" ]] && local APP="$TEST_APP" + + add_requirements_txt "$APP" "$APP_REPO_DIR" + mv -f "$APP_REPO_DIR/app-cron-cnb.json" "$APP_REPO_DIR/app.json" +} diff --git a/tests/unit/builder-railpack.bats b/tests/unit/builder-railpack.bats index 260062443..3806b2508 100644 --- a/tests/unit/builder-railpack.bats +++ b/tests/unit/builder-railpack.bats @@ -91,3 +91,44 @@ teardown() { assert_success assert_output_contains "SECRET_KEY=fjdkslafjdk" } + +@test "(builder-railpack) cron: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 cron_run_wrapper + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains 'create mise config' + assert_output_contains 'Successfully built image in' + + cron_id="$(dokku cron:list $TEST_APP --format json | jq -r '.[0].id')" + run /bin/bash -c "echo $cron_id" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_exists + + run /bin/bash -c "dokku cron:run $TEST_APP $cron_id" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "['task.py', 'some', 'cron', 'task']" +} + +cron_run_wrapper() { + local APP="$1" + local APP_REPO_DIR="$2" + [[ -z "$APP" ]] && local APP="$TEST_APP" + + add_requirements_txt "$APP" "$APP_REPO_DIR" + mv -f "$APP_REPO_DIR/app-cron.json" "$APP_REPO_DIR/app.json" +} From 7cfabe1322853ba17d431701ea6b172c544f67b1 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 4 Jan 2026 02:42:21 -0500 Subject: [PATCH 3/6] fix: move the correct file over --- tests/unit/builder-pack.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/builder-pack.bats b/tests/unit/builder-pack.bats index d8081f48e..008b0b2a3 100644 --- a/tests/unit/builder-pack.bats +++ b/tests/unit/builder-pack.bats @@ -183,5 +183,5 @@ cron_run_wrapper() { [[ -z "$APP" ]] && local APP="$TEST_APP" add_requirements_txt "$APP" "$APP_REPO_DIR" - mv -f "$APP_REPO_DIR/app-cron-cnb.json" "$APP_REPO_DIR/app.json" + mv -f "$APP_REPO_DIR/app-cnb-cron.json‎" "$APP_REPO_DIR/app.json" } From 8f9ca78642f9f89ac6d8a3403fd8d00e32391ab5 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 4 Jan 2026 03:38:44 -0500 Subject: [PATCH 4/6] chore: debug --- tests/unit/builder-pack.bats | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/builder-pack.bats b/tests/unit/builder-pack.bats index 008b0b2a3..5b50d68bf 100644 --- a/tests/unit/builder-pack.bats +++ b/tests/unit/builder-pack.bats @@ -183,5 +183,6 @@ cron_run_wrapper() { [[ -z "$APP" ]] && local APP="$TEST_APP" add_requirements_txt "$APP" "$APP_REPO_DIR" + ls -lah "$APP_REPO_DIR" mv -f "$APP_REPO_DIR/app-cnb-cron.json‎" "$APP_REPO_DIR/app.json" } From 9d603e1a45f64efa7d9b1b64d65c0cce290b9b17 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 4 Jan 2026 20:45:52 -0500 Subject: [PATCH 5/6] fix: use real path when extracting files --- tests/unit/builder-dockerfile.bats | 1 + tests/unit/builder-herokuish.bats | 1 + tests/unit/builder-nixpacks.bats | 1 + tests/unit/builder-pack.bats | 1 + tests/unit/builder-railpack.bats | 1 + tests/unit/test_helper.bash | 4 ++++ 6 files changed, 9 insertions(+) diff --git a/tests/unit/builder-dockerfile.bats b/tests/unit/builder-dockerfile.bats index d61e6379f..ca62231f0 100644 --- a/tests/unit/builder-dockerfile.bats +++ b/tests/unit/builder-dockerfile.bats @@ -205,6 +205,7 @@ cron_run_wrapper() { local APP="$1" local APP_REPO_DIR="$2" [[ -z "$APP" ]] && local APP="$TEST_APP" + APP_REPO_DIR="$(realpath "$APP_REPO_DIR")" convert_to_dockerfile "$APP" "$APP_REPO_DIR" mv -f "$APP_REPO_DIR/app-cron.json" "$APP_REPO_DIR/app.json" diff --git a/tests/unit/builder-herokuish.bats b/tests/unit/builder-herokuish.bats index f794e3ca2..a7a66bc11 100644 --- a/tests/unit/builder-herokuish.bats +++ b/tests/unit/builder-herokuish.bats @@ -158,6 +158,7 @@ cron_run_wrapper() { local APP="$1" local APP_REPO_DIR="$2" [[ -z "$APP" ]] && local APP="$TEST_APP" + APP_REPO_DIR="$(realpath "$APP_REPO_DIR")" mv -f "$APP_REPO_DIR/app-cron.json" "$APP_REPO_DIR/app.json" } diff --git a/tests/unit/builder-nixpacks.bats b/tests/unit/builder-nixpacks.bats index a7fd3ac6e..e7d97af25 100644 --- a/tests/unit/builder-nixpacks.bats +++ b/tests/unit/builder-nixpacks.bats @@ -117,6 +117,7 @@ cron_run_wrapper() { local APP="$1" local APP_REPO_DIR="$2" [[ -z "$APP" ]] && local APP="$TEST_APP" + APP_REPO_DIR="$(realpath "$APP_REPO_DIR")" add_requirements_txt "$APP" "$APP_REPO_DIR" mv -f "$APP_REPO_DIR/app-cron.json" "$APP_REPO_DIR/app.json" diff --git a/tests/unit/builder-pack.bats b/tests/unit/builder-pack.bats index 5b50d68bf..8f25784c2 100644 --- a/tests/unit/builder-pack.bats +++ b/tests/unit/builder-pack.bats @@ -181,6 +181,7 @@ cron_run_wrapper() { local APP="$1" local APP_REPO_DIR="$2" [[ -z "$APP" ]] && local APP="$TEST_APP" + APP_REPO_DIR="$(realpath "$APP_REPO_DIR")" add_requirements_txt "$APP" "$APP_REPO_DIR" ls -lah "$APP_REPO_DIR" diff --git a/tests/unit/builder-railpack.bats b/tests/unit/builder-railpack.bats index 3806b2508..27cf02663 100644 --- a/tests/unit/builder-railpack.bats +++ b/tests/unit/builder-railpack.bats @@ -128,6 +128,7 @@ cron_run_wrapper() { local APP="$1" local APP_REPO_DIR="$2" [[ -z "$APP" ]] && local APP="$TEST_APP" + APP_REPO_DIR="$(realpath "$APP_REPO_DIR")" add_requirements_txt "$APP" "$APP_REPO_DIR" mv -f "$APP_REPO_DIR/app-cron.json" "$APP_REPO_DIR/app.json" diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash index 95e89376d..3b581565a 100644 --- a/tests/unit/test_helper.bash +++ b/tests/unit/test_helper.bash @@ -574,6 +574,8 @@ add_requirements_txt() { local APP="$1" local APP_REPO_DIR="$2" [[ -z "$APP" ]] && local APP="$TEST_APP" + APP_REPO_DIR="$(realpath "$APP_REPO_DIR")" + echo "flask" >>"$APP_REPO_DIR/requirements.txt" } @@ -632,6 +634,8 @@ convert_to_dockerfile() { local APP="$1" local APP_REPO_DIR="$2" [[ -z "$APP" ]] && local APP="$TEST_APP" + APP_REPO_DIR="$(realpath "$APP_REPO_DIR")" + mv "$APP_REPO_DIR/dockerfile.Dockerfile" "$APP_REPO_DIR/Dockerfile" } From f64b87cc279e93530ab71838755f6c0e30120326 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 4 Jan 2026 22:03:59 -0500 Subject: [PATCH 6/6] fix: use correct path for app-cnb-cron.json --- tests/unit/builder-pack.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/builder-pack.bats b/tests/unit/builder-pack.bats index 8f25784c2..3721b2e62 100644 --- a/tests/unit/builder-pack.bats +++ b/tests/unit/builder-pack.bats @@ -185,5 +185,5 @@ cron_run_wrapper() { add_requirements_txt "$APP" "$APP_REPO_DIR" ls -lah "$APP_REPO_DIR" - mv -f "$APP_REPO_DIR/app-cnb-cron.json‎" "$APP_REPO_DIR/app.json" + mv -f "$APP_REPO_DIR/app-cnb-cron.json" "$APP_REPO_DIR/app.json" }