From e945087f792e80a59f4ff2eb93c2ec9f7a0a6c13 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Wed, 17 Jul 2024 02:12:35 +0200 Subject: [PATCH] test: env version writing tests --- tests/integration/app_deploy.bats | 31 ------- tests/integration/app_deploy_env_version.bats | 80 +++++++++++++++++++ .../app_deploy_remote_recipes.bats | 74 +++++++++++++++++ tests/integration/app_new.bats | 29 ++++++- .../integration/app_rollback_env_version.bats | 42 ++++++++++ .../integration/app_upgrade_env_version.bats | 41 ++++++++++ 6 files changed, 264 insertions(+), 33 deletions(-) create mode 100644 tests/integration/app_deploy_env_version.bats create mode 100644 tests/integration/app_deploy_remote_recipes.bats create mode 100644 tests/integration/app_rollback_env_version.bats create mode 100644 tests/integration/app_upgrade_env_version.bats diff --git a/tests/integration/app_deploy.bats b/tests/integration/app_deploy.bats index 1d341c04..8ba05f5d 100644 --- a/tests/integration/app_deploy.bats +++ b/tests/integration/app_deploy.bats @@ -355,34 +355,3 @@ teardown(){ run $ABRA app secret rm "$TEST_APP_DOMAIN" --all --chaos assert_success } - -# bats test_tags=slow -@test "deploy chaos commit" { - tagHash=$(_get_tag_hash "0.1.0+1.20.0") - - run $ABRA app deploy "$TEST_APP_DOMAIN" "$tagHash" --no-input --no-converge-checks - assert_success - assert_output --partial 'chaos mode' -} - -# bats test_tags=slow -@test "deploy remote recipe" { - run sed -i 's/TYPE=abra-test-recipe/RECIPE=git.coopcloud.tech\/coop-cloud\/abra-test-recipe/g' \ - "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" - assert_success - - run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input --no-converge-checks - assert_success - assert_output --partial "git.coopcloud.tech/coop-cloud/abra-test-recipe" -} - -# bats test_tags=slow -@test "deploy remote recipe with version" { - run sed -i 's/TYPE=abra-test-recipe/RECIPE=git.coopcloud.tech\/coop-cloud\/abra-test-recipe:0.2.0+1.21.0/g' \ - "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" - assert_success - - run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input --no-converge-checks - assert_success - assert_output --partial '0.2.0+1.21.0' -} diff --git a/tests/integration/app_deploy_env_version.bats b/tests/integration/app_deploy_env_version.bats new file mode 100644 index 00000000..63d4d775 --- /dev/null +++ b/tests/integration/app_deploy_env_version.bats @@ -0,0 +1,80 @@ +#!/usr/bin/env bash + +setup_file(){ + load "$PWD/tests/integration/helpers/common" + _common_setup + _add_server + _new_app +} + +teardown_file(){ + _rm_app + _rm_server + _reset_recipe +} + +setup(){ + load "$PWD/tests/integration/helpers/common" + _common_setup + _ensure_catalogue +} + +teardown(){ + _reset_recipe + _undeploy_app + _reset_app +} + +# bats test_tags=slow +@test "deploy version written to env" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.0+1.20.0" --no-input --no-converge-checks + assert_success + + run grep -q "TYPE=$TEST_RECIPE:0.1.0+1.20.0" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +} + +# bats test_tags=slow +@test "redeploy overwrites env version" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.0+1.20.0" --no-input --no-converge-checks + assert_success + + run grep -q "TYPE=$TEST_RECIPE:0.1.0+1.20.0" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success + + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.2.0+1.21.0" \ + --no-input --no-converge-checks --force + assert_success + + run grep -q "TYPE=$TEST_RECIPE:0.2.0+1.21.0" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +} + +# bats test_tags=slow +@test "chaos commit written to env" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "1e83340e" --no-input --no-converge-checks + assert_success + + run grep -q "TYPE=$TEST_RECIPE:1e83340e" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +} + +# bats test_tags=slow +@test "redeploy reads from env version" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.0+1.20.0" --no-input --no-converge-checks + assert_success + + run grep -q "TYPE=$TEST_RECIPE:0.1.0+1.20.0" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success + + _undeploy_app + + run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input --no-converge-checks + assert_success + assert_output --partial '0.1.0+1.20.0' +} diff --git a/tests/integration/app_deploy_remote_recipes.bats b/tests/integration/app_deploy_remote_recipes.bats new file mode 100644 index 00000000..56b6ce56 --- /dev/null +++ b/tests/integration/app_deploy_remote_recipes.bats @@ -0,0 +1,74 @@ +#!/usr/bin/env bash + +setup_file(){ + load "$PWD/tests/integration/helpers/common" + _common_setup + _add_server + _new_app +} + +teardown_file(){ + _rm_app + _rm_server + _reset_recipe +} + +setup(){ + load "$PWD/tests/integration/helpers/common" + _common_setup + _ensure_catalogue +} + +teardown(){ + _reset_recipe + _undeploy_app + _reset_app +} + +# bats test_tags=slow +@test "deploy remote recipe" { + run sed -i 's/TYPE=abra-test-recipe/TYPE=git.coopcloud.tech\/coop-cloud\/abra-test-recipe/g' \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success + + run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input --no-converge-checks + assert_success + assert_output --partial "git.coopcloud.tech/coop-cloud/abra-test-recipe" +} + +# bats test_tags=slow +@test "deploy remote recipe with version" { + run sed -i 's/TYPE=abra-test-recipe/TYPE=git.coopcloud.tech\/coop-cloud\/abra-test-recipe:0.2.0+1.21.0/g' \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success + + run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input --no-converge-checks + assert_success + assert_output --partial '0.2.0+1.21.0' +} + +# bats test_tags=slow +@test "deploy remote recipe with chaos commit" { + run sed -i 's/TYPE=abra-test-recipe/TYPE=git.coopcloud.tech\/coop-cloud\/abra-test-recipe:1e83340e/g' \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success + + run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input --no-converge-checks + assert_success + assert_output --partial '1e83340e' +} + +# bats test_tags=slow +@test "remote recipe version written to env" { + run sed -i 's/TYPE=abra-test-recipe/TYPE=git.coopcloud.tech\/coop-cloud\/abra-test-recipe/g' \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success + + run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input --no-converge-checks + assert_success + + latestRelease=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | tail -n 1) + run grep -q "TYPE=git.coopcloud.tech\/coop-cloud\/abra-test-recipe:$latestRelease" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +} diff --git a/tests/integration/app_new.bats b/tests/integration/app_new.bats index 9646b57a..d88b7404 100644 --- a/tests/integration/app_new.bats +++ b/tests/integration/app_new.bats @@ -39,17 +39,42 @@ teardown(){ _get_head_hash _get_current_hash assert_equal "$headHash" "$currentHash" + + latestRelease=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | tail -n 1) + run grep -q "TYPE=$TEST_RECIPE:$latestRelease" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success } @test "create new app with version" { - run $ABRA app new "$TEST_RECIPE" 0.1.1+1.20.2 \ + run $ABRA app new "$TEST_RECIPE" 0.3.0+1.21.0 \ --no-input \ --server "$TEST_SERVER" \ --domain "$TEST_APP_DOMAIN" assert_success assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" - assert_equal $(_get_tag_hash 0.1.1+1.20.2) $(_get_current_hash) + assert_equal $(_get_tag_hash 0.3.0+1.21.0) $(_get_current_hash) + + run grep -q "TYPE=$TEST_RECIPE:0.3.0+1.21.0" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +} + +@test "create new app with chaos commit" { + run $ABRA app new "$TEST_RECIPE" 1e83340e \ + --no-input \ + --server "$TEST_SERVER" \ + --domain "$TEST_APP_DOMAIN" + assert_success + assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + + currentHash=$(_get_current_hash) + assert_equal 1e83340e ${currentHash:0:8} + + run grep -q "TYPE=$TEST_RECIPE:1e83340e" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success } @test "does not overwrite existing env files" { diff --git a/tests/integration/app_rollback_env_version.bats b/tests/integration/app_rollback_env_version.bats new file mode 100644 index 00000000..a06d22a4 --- /dev/null +++ b/tests/integration/app_rollback_env_version.bats @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +setup_file(){ + load "$PWD/tests/integration/helpers/common" + _common_setup + _add_server + _new_app +} + +teardown_file(){ + _rm_app + _rm_server + _reset_recipe +} + +setup(){ + load "$PWD/tests/integration/helpers/common" + _common_setup +} + +teardown(){ + _undeploy_app + _reset_recipe +} + +@test "rollback writes version to env file" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.2.0+1.21.0" --no-input --no-converge-checks + assert_success + assert_output --partial "0.2.0+1.21.0" + + run grep -q "TYPE=abra-test-recipe:0.2.0+1.21.0" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success + + run $ABRA app rollback "$TEST_APP_DOMAIN" "0.1.0+1.20.0" --no-input --no-converge-checks + assert_success + assert_output --partial "0.1.0+1.20.0" + + run grep -q "TYPE=abra-test-recipe:0.1.0+1.20.0" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +} diff --git a/tests/integration/app_upgrade_env_version.bats b/tests/integration/app_upgrade_env_version.bats new file mode 100644 index 00000000..b4fa1c46 --- /dev/null +++ b/tests/integration/app_upgrade_env_version.bats @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +setup_file(){ + load "$PWD/tests/integration/helpers/common" + _common_setup + _add_server + _new_app +} + +teardown_file(){ + _rm_app + _rm_server +} + +setup(){ + load "$PWD/tests/integration/helpers/common" + _common_setup +} + +teardown(){ + _undeploy_app + _reset_recipe +} + +@test "upgrade writes version to env file" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.0+1.20.0" --no-input --no-converge-checks + assert_success + assert_output --partial '0.1.0+1.20.0' + + run grep -q "TYPE=abra-test-recipe:0.1.0+1.20.0" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success + + run $ABRA app upgrade "$TEST_APP_DOMAIN" "0.2.0+1.21.0" --no-input --no-converge-checks + assert_success + assert_output --partial "0.2.0+1.21.0" + + run grep -q "TYPE=abra-test-recipe:0.2.0+1.21.0" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +}