From 7292eaefc3b5374df165eee2e56c752aa395796e Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 10 Jul 2021 15:32:59 -0400 Subject: [PATCH] tests: add test for builder-pack:set projectoml-path --- tests/apps/python/cnb/1/bin/build | 15 +++++ tests/apps/python/cnb/1/bin/detect | 3 + tests/apps/python/cnb/1/buildpack.toml | 9 +++ tests/apps/python/cnb/2/bin/build | 21 +++++++ tests/apps/python/cnb/2/bin/detect | 3 + tests/apps/python/cnb/2/buildpack.toml | 9 +++ tests/apps/python/project2.toml | 10 ++++ tests/unit/builder-pack.bats | 81 ++++++++++++++++++++++++++ 8 files changed, 151 insertions(+) create mode 100755 tests/apps/python/cnb/1/bin/build create mode 100755 tests/apps/python/cnb/1/bin/detect create mode 100644 tests/apps/python/cnb/1/buildpack.toml create mode 100755 tests/apps/python/cnb/2/bin/build create mode 100755 tests/apps/python/cnb/2/bin/detect create mode 100644 tests/apps/python/cnb/2/buildpack.toml create mode 100644 tests/apps/python/project2.toml create mode 100644 tests/unit/builder-pack.bats diff --git a/tests/apps/python/cnb/1/bin/build b/tests/apps/python/cnb/1/bin/build new file mode 100755 index 000000000..93a8d56ae --- /dev/null +++ b/tests/apps/python/cnb/1/bin/build @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +layers_dir=$1 + +echo "Building with buildpack 1" +bp_layer=$layers_dir/1 +bp_env_dir=$bp_layer/env +mkdir -p $bp_env_dir + +echo "TESTENV_1" > $bp_env_dir/TESTENV + +echo "[types]" > ${bp_layer}.toml +echo "launch = true" >> ${bp_layer}.toml +echo "build = true" >> ${bp_layer}.toml +echo "cache = true" >> ${bp_layer}.toml diff --git a/tests/apps/python/cnb/1/bin/detect b/tests/apps/python/cnb/1/bin/detect new file mode 100755 index 000000000..98668b00f --- /dev/null +++ b/tests/apps/python/cnb/1/bin/detect @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +echo "1" && exit 0 diff --git a/tests/apps/python/cnb/1/buildpack.toml b/tests/apps/python/cnb/1/buildpack.toml new file mode 100644 index 000000000..f89645558 --- /dev/null +++ b/tests/apps/python/cnb/1/buildpack.toml @@ -0,0 +1,9 @@ +api = "0.6" + +[buildpack] +id = "1" +version = "0.1.0" +name = "1 Packages Buildpack" + +[[stacks]] +id = "heroku-20" diff --git a/tests/apps/python/cnb/2/bin/build b/tests/apps/python/cnb/2/bin/build new file mode 100755 index 000000000..7de333ff7 --- /dev/null +++ b/tests/apps/python/cnb/2/bin/build @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +layers_dir=$1 + +echo "Building with buildpack 2" +bp_layer=$layers_dir/2 +bp_env_dir=$bp_layer/env +mkdir -p $bp_env_dir + +export TESTENV="$TESTENV:anotherenv" + +echo "===> env start" +env +echo "===> env end" + +echo "TESTENV_2" > $bp_env_dir/TESTENV + +echo "[types]" > ${bp_layer}.toml +echo "launch = true" >> ${bp_layer}.toml +echo "build = true" >> ${bp_layer}.toml +echo "cache = true" >> ${bp_layer}.toml diff --git a/tests/apps/python/cnb/2/bin/detect b/tests/apps/python/cnb/2/bin/detect new file mode 100755 index 000000000..48d7cb887 --- /dev/null +++ b/tests/apps/python/cnb/2/bin/detect @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +echo "2" && exit 0 diff --git a/tests/apps/python/cnb/2/buildpack.toml b/tests/apps/python/cnb/2/buildpack.toml new file mode 100644 index 000000000..c15695e03 --- /dev/null +++ b/tests/apps/python/cnb/2/buildpack.toml @@ -0,0 +1,9 @@ +api = "0.6" + +[buildpack] +id = "2" +version = "0.1.0" +name = "2 Packages Buildpack" + +[[stacks]] +id = "heroku-20" diff --git a/tests/apps/python/project2.toml b/tests/apps/python/project2.toml new file mode 100644 index 000000000..e1a066cac --- /dev/null +++ b/tests/apps/python/project2.toml @@ -0,0 +1,10 @@ +[project] +id = "python" +name = "python" +version = "1.0.0" + +[[build.buildpacks]] +uri = "./cnb/1" + +[[build.buildpacks]] +uri = "./cnb/1" diff --git a/tests/unit/builder-pack.bats b/tests/unit/builder-pack.bats new file mode 100644 index 000000000..3835fcd03 --- /dev/null +++ b/tests/unit/builder-pack.bats @@ -0,0 +1,81 @@ +#!/usr/bin/env bats + +load test_helper + +setup_file() { + if ! command -v "pack" &>/dev/null; then + add-apt-repository --yes ppa:cncf-buildpacks/pack-cli + apt-get update + apt-get --yes install pack-cli + fi +} + +setup() { + create_app +} + +teardown() { + destroy_app +} + +@test "(builder-pack:set)" { + run /bin/bash -c "dokku builder:set $TEST_APP selected pack" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku buildpacks:set-property $TEST_APP stack heroku/buildpacks:20" + echo "output: $output" + echo "status: $status" + assert_success + + run deploy_app python dokku@dokku.me:$TEST_APP inject_requirements_txt + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains 'Building with buildpack 1' 0 + assert_output_contains 'Installing requirements with pip' + + run /bin/bash -c "dokku builder-pack:set $TEST_APP projecttoml-path nonexistent.toml" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku ps:rebuild $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains 'Building with buildpack 1' 0 + assert_output_contains 'Installing requirements with pip' + + run /bin/bash -c "dokku builder-pack:set $TEST_APP projecttoml-path project2.toml" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku ps:rebuild $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains 'Building with buildpack 1' + assert_output_contains 'Installing requirements with pip' 0 + + run /bin/bash -c "dokku builder-pack:set $TEST_APP projecttoml-path" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku ps:rebuild $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains 'Building with buildpack 1' 0 + assert_output_contains 'Installing requirements with pip' +} + +inject_requirements_txt() { + local APP="$1" + local APP_REPO_DIR="$2" + [[ -z "$APP" ]] && local APP="$TEST_APP" + echo "flask" >>"$APP_REPO_DIR/requirements.txt" +}