1
0
Fork 0
mirror of synced 2024-12-12 18:35:46 -05:00

Add tests for hooks

This commit is contained in:
Tim Byrne 2017-07-05 16:32:10 -05:00
parent 0168bcfb5e
commit 557ce93fab
No known key found for this signature in database
GPG key ID: 14DB4FC2465A4B12
2 changed files with 182 additions and 0 deletions

181
test/117_accept_hooks.bats Normal file
View file

@ -0,0 +1,181 @@
load common
load_fixtures
status=;output=; #; populated by bats run()
version_regex="yadm [[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+"
setup() {
destroy_tmp
build_repo
mkdir -p "$T_DIR_HOOKS"
}
function create_hook() {
hook_name="$1"
hook_exit="$2"
hook_file="$T_DIR_HOOKS/$hook_name"
{
echo "#!/bin/sh"
echo "echo ran $hook_name"
echo "env"
echo "exit $hook_exit"
} > "$hook_file"
chmod a+x "$hook_file"
}
@test "Hooks (no hook)" {
echo "
When no hook is present
do no not run the hook
run command
Exit with 0
"
#; run yadm with no command
run "${T_YADM_Y[@]}" version
[ $status -eq 0 ]
[[ "$output" =~ $version_regex ]]
}
@test "Hooks (successful pre hook)" {
echo "
When hook is present
run hook
run command
Exit with 0
"
create_hook "pre_version" "0"
#; run yadm with no command
run "${T_YADM_Y[@]}" version
[ $status -eq 0 ]
[[ "$output" =~ ran\ pre_version ]]
[[ "$output" =~ $version_regex ]]
}
@test "Hooks (unsuccessful pre hook)" {
echo "
When hook is present
run hook
report hook failure
do no not run command
Exit with 13
"
create_hook "pre_version" "13"
#; run yadm with no command
run "${T_YADM_Y[@]}" version
[ $status -eq 13 ]
[[ "$output" =~ ran\ pre_version ]]
[[ "$output" =~ pre_version\ was\ not\ successful ]]
[[ ! "$output" =~ $version_regex ]]
}
@test "Hooks (successful post hook)" {
echo "
When hook is present
run command
run hook
Exit with 0
"
create_hook "post_version" "0"
#; run yadm with no command
run "${T_YADM_Y[@]}" version
[ $status -eq 0 ]
[[ "$output" =~ $version_regex ]]
[[ "$output" =~ ran\ post_version ]]
}
@test "Hooks (unsuccessful post hook)" {
echo "
When hook is present
run command
run hook
Exit with 0
"
create_hook "post_version" "13"
#; run yadm with no command
run "${T_YADM_Y[@]}" version
[ $status -eq 0 ]
[[ "$output" =~ $version_regex ]]
[[ "$output" =~ ran\ post_version ]]
}
@test "Hooks (successful pre hook + post hook)" {
echo "
When hook is present
run hook
run command
run hook
Exit with 0
"
create_hook "pre_version" "0"
create_hook "post_version" "0"
#; run yadm with no command
run "${T_YADM_Y[@]}" version
[ $status -eq 0 ]
[[ "$output" =~ ran\ pre_version ]]
[[ "$output" =~ $version_regex ]]
[[ "$output" =~ ran\ post_version ]]
}
@test "Hooks (unsuccessful pre hook + post hook)" {
echo "
When hook is present
run hook
report hook failure
do no not run command
do no not run post hook
Exit with 13
"
create_hook "pre_version" "13"
create_hook "post_version" "0"
#; run yadm with no command
run "${T_YADM_Y[@]}" version
[ $status -eq 13 ]
[[ "$output" =~ ran\ pre_version ]]
[[ "$output" =~ pre_version\ was\ not\ successful ]]
[[ ! "$output" =~ $version_regex ]]
[[ ! "$output" =~ ran\ post_version ]]
}
@test "Hooks (environment variables)" {
echo "
When hook is present
run command
run hook
hook should have access to environment variables
Exit with 0
"
create_hook "post_version" "0"
#; run yadm with no command
run "${T_YADM_Y[@]}" version extra_args
[ $status -eq 0 ]
[[ "$output" =~ $version_regex ]]
[[ "$output" =~ ran\ post_version ]]
[[ "$output" =~ YADM_HOOK_COMMAND=version ]]
[[ "$output" =~ YADM_HOOK_EXIT=0 ]]
[[ "$output" =~ YADM_HOOK_FULL_COMMAND=version\ extra_args ]]
[[ "$output" =~ YADM_HOOK_REPO=${T_DIR_REPO} ]]
[[ "$output" =~ YADM_HOOK_WORK=${T_DIR_WORK} ]]
}

View file

@ -13,6 +13,7 @@ function load_fixtures() {
export T_DIR_YADM="$T_TMP/.yadm"
export T_DIR_WORK="$T_TMP/yadm-work"
export T_DIR_REPO="$T_DIR_YADM/repo.git"
export T_DIR_HOOKS="$T_DIR_YADM/hooks"
export T_YADM_CONFIG="$T_DIR_YADM/config"
export T_YADM_ENCRYPT="$T_DIR_YADM/encrypt"
export T_YADM_ARCHIVE="$T_DIR_YADM/files.gpg"