1
0
mirror of https://github.com/TheLocehiliosan/yadm synced 2024-10-27 20:34:27 +00:00
TheLocehiliosan_yadm/test/117_accept_hooks.bats
2017-07-05 16:33:50 -05:00

182 lines
3.6 KiB
Bash

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} ]]
}