0
0
forked from toolshed/abra

test: use more plumbung for git output

This commit is contained in:
decentral1se 2024-06-20 11:04:30 +02:00
parent 91ea2c01a5
commit 43990b6fae
Signed by untrusted user: decentral1se
GPG Key ID: 03789458B3D0C410
2 changed files with 43 additions and 37 deletions

View File

@ -13,6 +13,7 @@ teardown_file(){
setup(){ setup(){
load "$PWD/tests/integration/helpers/common" load "$PWD/tests/integration/helpers/common"
load "$PWD/tests/integration/helpers/git"
_common_setup _common_setup
_fetch_recipe _fetch_recipe
} }
@ -26,26 +27,9 @@ teardown(){
run $ABRA app new --generate-bash-completion run $ABRA app new --generate-bash-completion
assert_success assert_success
assert_output --partial "traefik" assert_output --partial "traefik"
assert_output --partial "abra-test-recipe"
# Note: this test needs to be updated when a new version of the test recipe is published.
run $ABRA app new abra-test-recipe --generate-bash-completion
assert_success
assert_output "0.1.0+1.20.0
0.1.1+1.20.2
0.2.0+1.21.0"
} }
@test "create new app" { @test "create new app" {
_fetch_recipe
_latest_tag
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" checkout $LATEST_TAG
assert_success
_latest_hash
_reset_recipe
run $ABRA app new "$TEST_RECIPE" \ run $ABRA app new "$TEST_RECIPE" \
--no-input \ --no-input \
--server "$TEST_SERVER" \ --server "$TEST_SERVER" \
@ -53,8 +37,9 @@ teardown(){
assert_success assert_success
assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" log -1 _get_head_hash
assert_output --partial "$LATEST_HASH" _get_current_hash
assert_equal "$headHash" "$currentHash"
} }
@test "create new app with version" { @test "create new app with version" {
@ -65,8 +50,9 @@ teardown(){
assert_success assert_success
assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" log -1 _get_tag_hash 0.1.1+1.20.2
assert_output --partial "453db7121c0a56a7a8f15378f18fe3bf21ccfdef" _get_current_hash
assert_equal "$tagHash" "$currentHash"
} }
@test "does not overwrite existing env files" { @test "does not overwrite existing env files" {
@ -126,11 +112,14 @@ teardown(){
} }
@test "ensure recipe up to date if no --offline" { @test "ensure recipe up to date if no --offline" {
_reset_recipe
_get_n_hash 3
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~3 run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~3
assert_success assert_success
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status _get_current_hash
assert_output --regexp 'behind .* 3 commits' assert_equal "$currentHash" "$nHash"
run $ABRA app new "$TEST_RECIPE" \ run $ABRA app new "$TEST_RECIPE" \
--no-input \ --no-input \
@ -139,18 +128,22 @@ teardown(){
assert_success assert_success
assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status _get_head_hash
assert_output --partial "up to date" _get_current_hash
assert_equal "$HEAD_HASH" "$CURRENT_HASH"
_reset_recipe _reset_recipe
} }
@test "ensure recipe not up to date if --offline" { @test "ensure recipe not up to date if --offline" {
_reset_recipe
_get_n_hash 3
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~3 run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~3
assert_success assert_success
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status _get_current_hash
assert_output --regexp 'behind .* 3 commits' assert_equal "$currentHash" "$nHash"
# NOTE(d1): need to use --chaos to force same commit # NOTE(d1): need to use --chaos to force same commit
run $ABRA app new "$TEST_RECIPE" \ run $ABRA app new "$TEST_RECIPE" \
@ -162,12 +155,13 @@ teardown(){
assert_success assert_success
assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status _get_current_hash
assert_output --regexp 'behind .* 3 commits' assert_equal "$currentHash" "$nHash"
_reset_recipe _reset_recipe
} }
# bats test_tags=slow
@test "generate secrets" { @test "generate secrets" {
run $ABRA app new "$TEST_RECIPE" \ run $ABRA app new "$TEST_RECIPE" \
--no-input \ --no-input \

View File

@ -37,14 +37,6 @@ _set_git_author() {
assert_success assert_success
} }
_latest_tag() {
export LATEST_TAG=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" describe --abbrev=0)
}
_latest_hash() {
export LATEST_HASH=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" log -1 --pretty=format:%h)
}
_git_commit() { _git_commit() {
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" add . run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" add .
assert_success assert_success
@ -52,3 +44,23 @@ _git_commit() {
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" commit -m "test: helpers/git.bash: _git_commit" run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" commit -m "test: helpers/git.bash: _git_commit"
assert_success assert_success
} }
_get_tag_hash() {
tagHash=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" rev-list -n 1 "$1")
assert_success
}
_get_head_hash() {
headHash=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" show -s --format="%H" HEAD)
assert_success
}
_get_current_hash() {
currentHash=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" show -s --format="%H")
assert_success
}
_get_n_hash() {
nHash=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" show -s --format="%H" "HEAD~$1")
assert_success
}