test: tag/git helpers & refactor [ci skip]

This commit is contained in:
decentral1se 2023-09-23 23:19:49 +02:00
parent 575bfbb0fb
commit ce7b4733d7
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
8 changed files with 52 additions and 75 deletions

View File

@ -94,6 +94,8 @@ teardown(){
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
refute_output --partial 'behind 3'
_reset_recipe "$TEST_RECIPE"
}
@test "ensure recipe not up to date if --offline" {
@ -118,6 +120,8 @@ teardown(){
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
refute_output --partial 'behind 3'
_reset_recipe "$TEST_RECIPE"
}
@test "detect backup labels" {

View File

@ -75,12 +75,11 @@ setup(){
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
refute_output --partial 'behind 3'
_reset_recipe "$TEST_RECIPE"
}
@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
@ -93,11 +92,7 @@ setup(){
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'
_reset_recipe "$TEST_RECIPE"
}
@test "error if missing .env.sample" {

View File

@ -85,12 +85,11 @@ teardown(){
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
refute_output --partial 'behind 3'
_reset_recipe "$TEST_RECIPE"
}
@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
@ -104,11 +103,7 @@ teardown(){
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'
_reset_recipe "$TEST_RECIPE"
}
@test "error if missing arguments without passing --local" {

View File

@ -86,12 +86,7 @@ teardown(){
run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input --no-converge-checks
assert_success
# NOTE(d1): nuke it to ensure clean git state
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE"
assert_success
assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE"
_fetch_recipe "$TEST_RECIPE"
_reset_recipe "$TEST_RECIPE"
_undeploy_app
}
@ -112,30 +107,14 @@ teardown(){
assert_output --partial 'behind 3'
_undeploy_app
# NOTE(d1): nuke it to ensure clean git state
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE"
assert_success
assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE"
_fetch_recipe "$TEST_RECIPE"
_reset_recipe "$TEST_RECIPE"
}
# bats test_tags=slow
@test "deploy latest commit if no published versions and no --chaos" {
latestCommit="$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" rev-parse --short HEAD)"
run bash -c 'git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | wc -l'
assert_success
refute_output '0'
run bash -c 'git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | \
xargs -I{} git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -d {}'
assert_success
assert_output --partial 'Deleted tag'
run bash -c 'git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | wc -l'
assert_success
assert_output '0'
_remove_tags
# NOTE(d1): need to pass --offline to stop tags being pulled again
run $ABRA app deploy "$TEST_APP_DOMAIN" \
@ -146,13 +125,7 @@ teardown(){
refute_output --partial 'chaos'
_undeploy_app
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" fetch --all
assert_success
run bash -c 'git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | wc -l'
assert_success
refute_output '0'
_reset_tags
}
# bats test_tags=slow
@ -175,12 +148,7 @@ teardown(){
assert_output --partial 'chaos'
_undeploy_app
# NOTE(d1): nuke it to ensure clean git state
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE"
assert_success
assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE"
_fetch_recipe "$TEST_RECIPE"
_reset_recipe
}
# bats test_tags=slow

View File

@ -78,11 +78,7 @@ teardown(){
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" checkout "$latestCommit"
assert_success
# NOTE(d1): nuke it to ensure clean git state
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE"
assert_success
assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE"
_fetch_recipe "$TEST_RECIPE"
_reset_recipe "$TEST_RECIPE"
}
@test "bail if unstaged changes and no --chaos" {

View File

@ -1,11 +1,30 @@
#!/usr/bin/env bash
_checkout_recipe() {
if [[ -z "$1" ]]; then
echo 'forgot to pass argument to function?'
exit 1
fi
run git -C "$ABRA_DIR/recipes/$1" checkout .
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" checkout .
assert_success
}
_remove_tags(){
run bash -c 'git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | wc -l'
assert_success
refute_output '0'
run bash -c 'git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | \
xargs -I{} git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -d {}'
assert_success
assert_output --partial 'Deleted tag'
run bash -c 'git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | wc -l'
assert_success
assert_output '0'
}
_reset_tags() {
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" fetch --all
assert_success
run bash -c 'git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | wc -l'
assert_success
refute_output '0'
}

View File

@ -1,16 +1,19 @@
#!/usr/bin/env bash
_fetch_recipe() {
if [[ -z "$1" ]]; then
echo 'forgot to pass argument to function?'
exit 1
fi
if [[ ! -d "$ABRA_DIR/recipes/$1" ]]; then
if [[ ! -d "$ABRA_DIR/recipes/$TEST_RECIPE" ]]; then
run mkdir -p "$ABRA_DIR/recipes"
assert_success
run git clone "https://git.coopcloud.tech/coop-cloud/$1" "$ABRA_DIR/recipes/$1"
run git clone "https://git.coopcloud.tech/coop-cloud/$TEST_RECIPE" "$ABRA_DIR/recipes/$TEST_RECIPE"
assert_success
fi
}
_reset_recipe(){
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE"
assert_success
assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE"
_fetch_recipe
}

View File

@ -100,8 +100,5 @@ setup(){
assert_output --partial '0.1.0+1.20.0'
assert_output --regexp '0\.2\.0\+1\.2.*'
# NOTE(d1): nuke it since we can't clean up the tag
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE"
assert_success
assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE"
_reset_recipe "$TEST_RECIPE"
}