abra/tests/integration/recipe_lint.bats

107 lines
2.6 KiB
Plaintext
Raw Normal View History

2023-09-07 16:50:25 +00:00
#!/usr/bin/env bash
setup_file(){
2023-09-25 09:27:36 +00:00
load "$PWD/tests/integration/helpers/common"
_common_setup
_fetch_recipe
2023-09-25 08:52:27 +00:00
}
2023-09-07 16:50:25 +00:00
setup() {
load "$PWD/tests/integration/helpers/common"
_common_setup
}
teardown(){
_reset_recipe
}
2023-09-07 16:50:25 +00:00
@test "recipe lint" {
run $ABRA recipe lint gitea
assert_success
assert_output --partial 'compose config has expected version'
}
2023-09-21 07:07:00 +00:00
@test "retrieve recipe if missing" {
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE"
assert_success
assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE"
2023-09-07 16:50:25 +00:00
run $ABRA recipe lint "$TEST_RECIPE"
assert_success
2023-09-21 07:07:00 +00:00
assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE"
}
@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
2023-09-07 16:50:25 +00:00
assert_success
2023-09-21 07:07:00 +00:00
assert_output --partial 'foo'
2023-09-07 16:50:25 +00:00
run $ABRA recipe lint "$TEST_RECIPE"
2023-09-21 07:07:00 +00:00
assert_failure
assert_output --partial 'locally unstaged changes'
2023-09-07 16:50:25 +00:00
2023-09-21 07:07:00 +00:00
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
2023-09-07 16:50:25 +00:00
}
2023-09-21 07:07:00 +00:00
@test "do not bail if unstaged changes and --chaos" {
run bash -c "echo foo >> $ABRA_DIR/recipes/$TEST_RECIPE/foo"
assert_success
assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
2023-09-07 16:50:25 +00:00
2023-09-21 07:07:00 +00:00
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status
assert_success
assert_output --partial 'foo'
run $ABRA recipe lint "$TEST_RECIPE" --chaos
assert_success
2023-09-07 16:50:25 +00:00
2023-09-21 07:07:00 +00:00
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
}
@test "ensure recipe up to date if no --offline" {
wantHash=$(_get_n_hash 3)
2023-09-07 16:50:25 +00:00
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~3
assert_success
assert_equal $(_get_current_hash) "$wantHash"
2023-09-07 16:50:25 +00:00
run $ABRA recipe lint "$TEST_RECIPE"
assert_success
assert_equal $(_get_head_hash) $(_get_current_hash)
2023-09-21 07:07:00 +00:00
}
@test "ensure recipe not up to date if --offline" {
wantHash=$(_get_n_hash 3)
2023-09-21 07:07:00 +00:00
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~3
assert_success
assert_equal $(_get_current_hash) "$wantHash"
2023-09-21 07:07:00 +00:00
run $ABRA recipe lint "$TEST_RECIPE" --offline
assert_success
assert_equal $(_get_current_hash) "$wantHash"
2023-09-07 16:50:25 +00:00
}
2023-09-21 07:07:00 +00:00
@test "recipe lint warns on error" {
run $ABRA recipe lint "$TEST_RECIPE"
assert_success
refute_output --partial 'watch out, some critical errors are present'
run sed -i '/traefik.enable=.*/d' "$ABRA_DIR/recipes/$TEST_RECIPE/compose.yml"
assert_success
run $ABRA recipe lint "$TEST_RECIPE" --chaos
assert_success --partial 'watch out, some critical errors are present'
}