From c19cb81c4bed34908d443a5247f0d4558f436e2d Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 4 Jan 2026 00:39:06 -0500 Subject: [PATCH] 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" +}