test: less fragile integration suite [ci skip]

See coop-cloud/organising#584
See coop-cloud/organising#595
This commit is contained in:
2024-06-22 16:40:07 +02:00
parent a9ce2106c6
commit 2014cd6622
39 changed files with 249 additions and 425 deletions

View File

@ -1,7 +1,6 @@
#!/usr/bin/env bash
setup_file(){
load "$PWD/tests/integration/helpers/git"
load "$PWD/tests/integration/helpers/common"
_common_setup
_add_server
@ -17,14 +16,16 @@ teardown_file(){
setup(){
load "$PWD/tests/integration/helpers/common"
_common_setup
_reset_recipe
}
teardown(){
# https://github.com/bats-core/bats-core/issues/383#issuecomment-738628888
if [[ -z "${BATS_TEST_COMPLETED}" ]]; then
_undeploy_app
fi
_undeploy_app
_reset_recipe
_reset_app
_reset_tags
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
}
@test "validate app argument" {
@ -50,11 +51,6 @@ teardown(){
assert_failure
assert_output --partial 'locally unstaged changes'
refute_output --partial 'chaos'
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
_checkout_recipe
}
# bats test_tags=slow
@ -71,56 +67,42 @@ teardown(){
--chaos --no-input --no-converge-checks
assert_success
assert_output --partial 'chaos'
_undeploy_app
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
}
# bats test_tags=slow
@test "ensure recipe up to date if no --offline" {
wantHash=$(_get_n_hash 3)
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~3
assert_success
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
assert_output --regexp 'behind .* 3 commits'
assert_equal $(_get_current_hash) "$wantHash"
run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input --no-converge-checks
assert_success
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
refute_output --regexp 'behind .* 3 commits'
_reset_recipe
_undeploy_app
assert_equal $(_get_head_hash) $(_get_current_hash)
}
# bats test_tags=slow
@test "ensure recipe not up to date if --offline" {
wantHash=$(_get_n_hash 3)
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~3
assert_success
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
assert_output --regexp 'behind .* 3 commits'
assert_equal $(_get_current_hash) "$wantHash"
# NOTE(d1): need to use --chaos to force same commit
run $ABRA app deploy "$TEST_APP_DOMAIN" \
--no-input --no-converge-checks --chaos --offline
assert_success
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
assert_output --regexp 'behind .* 3 commits'
_undeploy_app
_reset_recipe
assert_equal $(_get_current_hash) "$wantHash"
}
# bats test_tags=slow
@test "deploy latest commit if no published versions and no --chaos" {
# TODO(d1): fix with a new test recipe which has no published versions?
skip "known issue, abra-test-recipe has published versions now"
latestCommit="$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" rev-parse --short HEAD)"
_remove_tags
@ -132,32 +114,22 @@ teardown(){
assert_output --partial "$latestCommit"
assert_output --partial 'using latest commit'
refute_output --partial 'chaos'
_undeploy_app
_reset_tags
}
# bats test_tags=slow
@test "ensure same commit if --chaos" {
latestCommit="$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" rev-parse --short HEAD)"
wantHash=$(_get_n_hash 3)
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~3
assert_success
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
assert_output --regexp 'behind .* 3 commits'
threeCommitsBack="$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" rev-parse --short HEAD)"
assert_equal $(_get_current_hash) "$wantHash"
run $ABRA app deploy "$TEST_APP_DOMAIN" \
--no-input --no-converge-checks --chaos
assert_success
refute_output --partial "$latestCommit"
assert_output --partial "$threeCommitsBack"
assert_output --partial "${wantHash:0:8}"
assert_output --partial 'chaos'
_undeploy_app
_reset_recipe
}
# bats test_tags=slow
@ -169,8 +141,6 @@ teardown(){
run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input --no-converge-checks
assert_success
_undeploy_app
assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE"
}
@ -182,8 +152,6 @@ teardown(){
--no-input --no-converge-checks --chaos
assert_failure
assert_output --partial 'failed lint checks'
_checkout_recipe
}
# bats test_tags=slow
@ -194,8 +162,6 @@ teardown(){
--no-input --no-converge-checks
assert_failure
assert_output --partial 'already deployed'
_undeploy_app
}
# bats test_tags=slow
@ -213,8 +179,6 @@ teardown(){
assert_success
assert_output --partial 'already deployed but continuing'
assert_output --partial '--chaos'
_undeploy_app
}
# bats test_tags=slow
@ -240,9 +204,6 @@ teardown(){
run $ABRA app secret remove "gitea.$TEST_SERVER" --all --no-input
assert_success
# NOTE(d1): to let the stack come down before nuking volumes
sleep 5
run $ABRA app volume remove "gitea.$TEST_SERVER" --no-input
assert_success
@ -277,6 +238,7 @@ teardown(){
assert_success
}
# bats test_tags=dns
@test "ensure domain is checked" {
if [[ "$TEST_SERVER" == "default" ]]; then
skip "domain checks are disabled for local server"
@ -302,8 +264,6 @@ teardown(){
--no-input --no-converge-checks --no-domain-checks
assert_success
assert_output --partial 'skipping domain checks as requested'
_undeploy_app
}
@test "error if specific version does not exist" {
@ -317,8 +277,6 @@ teardown(){
run $ABRA app deploy "$TEST_APP_DOMAIN" "0.2.0+1.21.0" --no-input
assert_success
assert_output --partial "0.2.0+1.21.0"
_undeploy_app
}
@test "bail out if specific version and chaos" {
@ -330,8 +288,6 @@ teardown(){
# bats test_tags=slow
@test "COMPOSE_FILE with \$COMPOSE_FILE override works" {
_reset_recipe
run sed -i 's/#COMPOSE_FILE="$COMPOSE_FILE:compose.extra_env.yml"/COMPOSE_FILE="$COMPOSE_FILE:compose.extra_env.yml"/g' \
"$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
assert_success
@ -342,9 +298,6 @@ teardown(){
assert_success
assert_output --partial "compose.yml"
assert_output --partial "compose.extra_env.yml"
_undeploy_app
_reset_app
}
@test "error if no secrets generated" {
@ -359,8 +312,6 @@ teardown(){
run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input --no-converge-checks
assert_failure
assert_output --partial 'unable to deploy, secrets not generated'
_reset_app
}
# bats test_tags=slow
@ -393,15 +344,15 @@ teardown(){
_git_commit
# NOTE(d1): 0.1.1+1.20.2 is a previous version which includes compose.extra_secret.yml
run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.1+1.20.2" --no-input --no-converge-checks
run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.1+1.20.2" \
--no-input --no-converge-checks
assert_success
refute_output --partial 'no such file or directory'
_undeploy_app
_reset_app
run $ABRA app secret rm "$TEST_APP_DOMAIN" --all
# TODO(d1): use of `--chaos` is a hack while the following is not fixed
# https://git.coopcloud.tech/coop-cloud/organising/issues/620
run $ABRA app secret rm "$TEST_APP_DOMAIN" --all --chaos
assert_success
_reset_recipe
}