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..ca62231f0 100644 --- a/tests/unit/builder-dockerfile.bats +++ b/tests/unit/builder-dockerfile.bats @@ -170,3 +170,43 @@ 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" + 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 fb1536f91..a7a66bc11 100644 --- a/tests/unit/builder-herokuish.bats +++ b/tests/unit/builder-herokuish.bats @@ -123,3 +123,42 @@ 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" + 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 e66a6147a..e7d97af25 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 @@ -81,9 +81,44 @@ teardown() { assert_output_contains "SECRET_KEY=fjdkslafjdk" } -inject_requirements_txt() { +@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" - echo "flask" >>"$APP_REPO_DIR/requirements.txt" + 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 55c662149..3721b2e62 100644 --- a/tests/unit/builder-pack.bats +++ b/tests/unit/builder-pack.bats @@ -143,3 +143,47 @@ 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" + APP_REPO_DIR="$(realpath "$APP_REPO_DIR")" + + 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" +} diff --git a/tests/unit/builder-railpack.bats b/tests/unit/builder-railpack.bats index a904e553b..27cf02663 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 @@ -92,9 +92,44 @@ teardown() { assert_output_contains "SECRET_KEY=fjdkslafjdk" } -inject_requirements_txt() { +@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" - echo "flask" >>"$APP_REPO_DIR/requirements.txt" + 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" }