tests: add a test to prove cron:run commands work as expected

Closes #8242
This commit is contained in:
Jose Diaz-Gonzalez
2026-01-04 00:39:06 -05:00
parent b1ebd694e6
commit c19cb81c4b
8 changed files with 260 additions and 1 deletions

View File

@@ -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"
}
}
}

View File

@@ -18,4 +18,4 @@
"predeploy": "touch /workspace/predeploy.test"
}
}
}
}

View File

@@ -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"
}
}
}

View File

@@ -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"
}

View File

@@ -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"
}

View File

@@ -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"
}

View File

@@ -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"
}

View File

@@ -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"
}