233 lines
6.3 KiB
Bash
233 lines
6.3 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
setup_file(){
|
|
load "$PWD/tests/integration/helpers/common"
|
|
_common_setup
|
|
_add_server
|
|
_new_app
|
|
}
|
|
|
|
teardown_file(){
|
|
_rm_server
|
|
}
|
|
|
|
setup(){
|
|
load "$PWD/tests/integration/helpers/common"
|
|
_common_setup
|
|
}
|
|
|
|
# TODO(d1): test "no available downgrades" when this is implemented
|
|
# https://git.coopcloud.tech/coop-cloud/organising/issues/204
|
|
|
|
@test "validate app argument" {
|
|
run $ABRA app rollback
|
|
assert_failure
|
|
assert_output --partial 'no app provided'
|
|
|
|
run $ABRA app rollback DOESNTEXIST
|
|
assert_failure
|
|
assert_output --partial 'cannot find app'
|
|
}
|
|
|
|
@test "retrieve recipe if missing" {
|
|
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE"
|
|
assert_success
|
|
assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE"
|
|
|
|
run $ABRA app rollback "$TEST_APP_DOMAIN" --no-input --no-converge-checks
|
|
assert_failure
|
|
assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE"
|
|
}
|
|
|
|
@test "ensure recipe up to date if no --offline" {
|
|
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 --partial 'behind 3'
|
|
|
|
run $ABRA app rollback "$TEST_APP_DOMAIN" --no-input --no-converge-checks
|
|
assert_failure
|
|
|
|
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
|
|
refute_output --partial 'behind 3'
|
|
}
|
|
|
|
@test "ensure recipe not up to date if --offline" {
|
|
latestCommit="$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" rev-parse --short HEAD)"
|
|
refute [ -z "$latestCommit" ];
|
|
|
|
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 --partial 'behind 3'
|
|
|
|
run $ABRA app rollback "$TEST_APP_DOMAIN" \
|
|
--no-input --no-converge-checks --offline
|
|
assert_failure
|
|
|
|
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
|
|
assert_output --partial 'behind 3'
|
|
|
|
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" checkout "$latestCommit"
|
|
assert_success
|
|
|
|
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
|
|
refute_output --partial 'behind 3'
|
|
}
|
|
|
|
@test "bail if unstaged changes and no --chaos" {
|
|
run bash -c "echo foo >> $ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
|
assert_success
|
|
assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
|
|
|
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
|
|
assert_success
|
|
assert_output --partial 'foo'
|
|
|
|
run $ABRA app rollback "$TEST_APP_DOMAIN" --no-input --no-converge-checks
|
|
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"
|
|
}
|
|
|
|
# bats test_tags=slow
|
|
@test "do not bail if unstaged changes and --chaos" {
|
|
run bash -c 'echo "unstaged changes" >> "$ABRA_DIR/recipes/$TEST_RECIPE/foo"'
|
|
assert_success
|
|
assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
|
|
|
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
|
|
assert_success
|
|
assert_output --partial 'foo'
|
|
|
|
run $ABRA app deploy "$TEST_APP_DOMAIN" \
|
|
--chaos --no-input --no-converge-checks
|
|
assert_success
|
|
assert_output --partial 'chaos'
|
|
|
|
run $ABRA app rollback "$TEST_APP_DOMAIN" \
|
|
--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 same commit if --chaos" {
|
|
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" checkout main
|
|
assert_success
|
|
|
|
latestCommit="$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" rev-parse --short HEAD)"
|
|
|
|
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 --partial 'behind 3'
|
|
|
|
threeCommitsBack="$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" rev-parse --short HEAD)"
|
|
|
|
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 'chaos'
|
|
|
|
run $ABRA app rollback "$TEST_APP_DOMAIN" \
|
|
--chaos --no-input --no-converge-checks
|
|
assert_success
|
|
refute_output --partial "$latestCommit"
|
|
assert_output --partial "$threeCommitsBack"
|
|
assert_output --partial 'chaos'
|
|
|
|
_undeploy_app
|
|
|
|
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" checkout "$latestCommit"
|
|
assert_success
|
|
refute_output --partial 'behind 3'
|
|
}
|
|
|
|
# bats test_tags=slow
|
|
@test "no rollback if lint error" {
|
|
_deploy_app
|
|
|
|
run sed -i '/traefik.enable=.*/d' "$ABRA_DIR/recipes/$TEST_RECIPE/compose.yml"
|
|
assert_success
|
|
|
|
run $ABRA app rollback "$TEST_APP_DOMAIN" --no-input --chaos
|
|
assert_failure
|
|
assert_output --partial 'failed lint checks'
|
|
|
|
_undeploy_app
|
|
|
|
_checkout_recipe "$TEST_RECIPE"
|
|
}
|
|
|
|
@test "error if not already deployed" {
|
|
run $ABRA app rollback "$TEST_APP_DOMAIN" --no-input --chaos
|
|
assert_failure
|
|
assert_output --partial 'not deployed'
|
|
}
|
|
|
|
# bats test_tags=slow
|
|
@test "error if no published release and no --chaos" {
|
|
_deploy_app
|
|
|
|
run $ABRA app rollback "$TEST_APP_DOMAIN" --no-input
|
|
assert_failure
|
|
assert_output --partial 'no published releases'
|
|
|
|
_undeploy_app
|
|
}
|
|
|
|
# bats test_tags=slow
|
|
@test "rollback to previous version" {
|
|
latestVersion=$(jq -r '.gitea.versions[-1] | keys[0]' < "$ABRA_DIR/catalogue/recipes.json")
|
|
refute [ -z "$latestVersion" ];
|
|
|
|
rollbackVersion=$(jq -r '.gitea.versions[-2] | keys[0]' < "$ABRA_DIR/catalogue/recipes.json")
|
|
refute [ -z "$rollbackVersion" ];
|
|
|
|
run $ABRA app new gitea \
|
|
--no-input \
|
|
--server "$TEST_SERVER" \
|
|
--domain "gitea.$TEST_SERVER" \
|
|
--secrets
|
|
assert_success
|
|
assert_exists "$ABRA_DIR/servers/$TEST_SERVER/gitea.$TEST_SERVER.env"
|
|
|
|
run $ABRA app deploy "gitea.$TEST_SERVER" --no-input --no-converge-checks
|
|
assert_success
|
|
assert_output --partial "$latestVersion"
|
|
|
|
run $ABRA app rollback "gitea.$TEST_SERVER" --no-input --no-converge-checks
|
|
assert_success
|
|
assert_output --partial "$rollbackVersion"
|
|
|
|
run $ABRA app undeploy "gitea.$TEST_SERVER" --no-input
|
|
assert_success
|
|
|
|
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
|
|
|
|
run $ABRA app remove "gitea.$TEST_SERVER" --no-input
|
|
assert_success
|
|
assert_not_exists "$ABRA_DIR/servers/$TEST_SERVER/gitea.$TEST_SERVER.env"
|
|
}
|