Create tests for class support in alt-links (#21)

This commit is contained in:
Tim Byrne 2017-01-20 00:13:56 -06:00
parent 3b4c405d7f
commit d7abc7ff41
No known key found for this signature in database
GPG Key ID: 6CBE24C2FD8CF76E
3 changed files with 319 additions and 143 deletions

View File

@ -3,6 +3,7 @@ load_fixtures
status=;output=; #; populated by bats run()
IN_REPO=(alt* "dir one")
export TEST_TREE_WITH_ALT=1
function create_encrypt() {
for efile in "encrypted-base##" "encrypted-system##$T_SYS" "encrypted-host##$T_SYS.$T_HOST" "encrypted-user##$T_SYS.$T_HOST.$T_USER"; do

View File

@ -3,6 +3,7 @@ load_fixtures
status=;output=; #; populated by bats run()
IN_REPO=(wild*)
export TEST_TREE_WITH_WILD=1
setup() {
destroy_tmp
@ -63,6 +64,27 @@ function test_alt() {
done
}
@test "Command 'alt' (wild class)" {
echo "
When the command 'alt' is provided
and file matches only ##CLASS
with possible wildcards
Report the linking
Verify correct file is linked
Exit with 0
"
git config --file="$T_YADM_CONFIG" alt.class set_class
for WILD_C in 'local' 'wild'; do
local c_base="wild-class-$WILD_C"
case $WILD_C in local) WILD_C="set_class";; wild) WILD_C="%";; esac
local match="${c_base}##${WILD_C}"
echo test_alt "$c_base" "$match"
test_alt "$c_base" "$match"
done
}
@test "Command 'alt' (wild host)" {
echo "
When the command 'alt' is provided
@ -86,6 +108,31 @@ function test_alt() {
done
}
@test "Command 'alt' (wild class-system)" {
echo "
When the command 'alt' is provided
and file matches only ##CLASS.SYSTEM
with possible wildcards
Report the linking
Verify correct file is linked
Exit with 0
"
git config --file="$T_YADM_CONFIG" alt.class set_class
for WILD_C in 'local' 'wild'; do
local c_base="wild-class-system-$WILD_C"
case $WILD_C in local) WILD_C="set_class";; wild) WILD_C="%";; esac
for WILD_S in 'local' 'wild'; do
local s_base="${c_base}-$WILD_S"
case $WILD_S in local) WILD_S="$T_SYS";; wild) WILD_S="%";; esac
local match="${s_base}##${WILD_C}.${WILD_S}"
echo test_alt "$s_base" "$match"
test_alt "$s_base" "$match"
done
done
}
@test "Command 'alt' (wild user)" {
echo "
When the command 'alt' is provided
@ -112,3 +159,65 @@ function test_alt() {
done
done
}
@test "Command 'alt' (wild class-system-host)" {
echo "
When the command 'alt' is provided
and file matches only ##CLASS.SYSTEM.HOST
with possible wildcards
Report the linking
Verify correct file is linked
Exit with 0
"
git config --file="$T_YADM_CONFIG" alt.class set_class
for WILD_C in 'local' 'wild'; do
local c_base="wild-class-system-host-$WILD_C"
case $WILD_C in local) WILD_C="set_class";; wild) WILD_C="%";; esac
for WILD_S in 'local' 'wild'; do
local s_base="${c_base}-$WILD_S"
case $WILD_S in local) WILD_S="$T_SYS";; wild) WILD_S="%";; esac
for WILD_H in 'local' 'wild'; do
local h_base="${s_base}-$WILD_H"
case $WILD_H in local) WILD_H="$T_HOST";; wild) WILD_H="%";; esac
local match="${h_base}##${WILD_C}.${WILD_S}.${WILD_H}"
echo test_alt "$h_base" "$match"
test_alt "$h_base" "$match"
done
done
done
}
@test "Command 'alt' (wild class-system-host-user)" {
echo "
When the command 'alt' is provided
and file matches only ##CLASS.SYSTEM.HOST.USER
with possible wildcards
Report the linking
Verify correct file is linked
Exit with 0
"
git config --file="$T_YADM_CONFIG" alt.class set_class
for WILD_C in 'local' 'wild'; do
local c_base="wild-class-system-host-user-$WILD_C"
case $WILD_C in local) WILD_C="set_class";; wild) WILD_C="%";; esac
for WILD_S in 'local' 'wild'; do
local s_base="${c_base}-$WILD_S"
case $WILD_S in local) WILD_S="$T_SYS";; wild) WILD_S="%";; esac
for WILD_H in 'local' 'wild'; do
local h_base="${s_base}-$WILD_H"
case $WILD_H in local) WILD_H="$T_HOST";; wild) WILD_H="%";; esac
for WILD_U in 'local' 'wild'; do
local u_base="${h_base}-$WILD_U"
case $WILD_U in local) WILD_U="$T_USER";; wild) WILD_U="%";; esac
local match="${u_base}##${WILD_C}.${WILD_S}.${WILD_H}.${WILD_U}"
echo test_alt "$u_base" "$match"
test_alt "$u_base" "$match"
done
done
done
done
}

View File

@ -81,6 +81,7 @@ function create_worktree() {
rm -rf "$DIR_WORKTREE"
#; create some standard files
if [ ! -z "$TEST_TREE_WITH_ALT" ] ; then
for f in \
"alt-none##S" \
"alt-none##S.H" \
@ -182,22 +183,14 @@ function create_worktree() {
"dir one/alt-override-user##$T_SYS.$T_HOST.custom_user/file1" \
"dir one/alt-override-user##$T_SYS.$T_HOST.custom_user/file2" \
"dir2/file2" \
.bash_profile \
.gnupg/gpg.conf \
.gnupg/pubring.gpg \
.gnupg/secring.gpg \
.hammerspoon/init.lua \
.ssh/config \
.ssh/secret.key \
.ssh/secret.pub \
.tmux.conf \
.vimrc \
;
do
make_parents "$DIR_WORKTREE/$f"
echo "$f" > "$DIR_WORKTREE/$f"
done
fi
if [ ! -z "$TEST_TREE_WITH_WILD" ] ; then
#; wildcard test data - yes this is a big mess :(
#; none
for f in "wild-none##"; do
@ -240,6 +233,79 @@ function create_worktree() {
done
done
done
#; class
for WILD_C in 'local' 'wild' 'other'; do
local c_base="wild-class-$WILD_C"
case $WILD_C in local) WILD_C="set_class";; wild) WILD_C="%";; esac
local f="${c_base}##${WILD_C}"
make_parents "$DIR_WORKTREE/$f"
echo "$f" > "$DIR_WORKTREE/$f"
done
#; class.system
for WILD_C in 'local' 'wild' 'other'; do
local c_base="wild-class-system-$WILD_C"
case $WILD_C in local) WILD_C="set_class";; wild) WILD_C="%";; esac
for WILD_S in 'local' 'wild' 'other'; do
local s_base="${c_base}-$WILD_S"
case $WILD_S in local) WILD_S="$T_SYS";; wild) WILD_S="%";; esac
local f="${s_base}##${WILD_C}.${WILD_S}"
make_parents "$DIR_WORKTREE/$f"
echo "$f" > "$DIR_WORKTREE/$f"
done
done
#; class.system.host
for WILD_C in 'local' 'wild' 'other'; do
local c_base="wild-class-system-host-$WILD_C"
case $WILD_C in local) WILD_C="set_class";; wild) WILD_C="%";; esac
for WILD_S in 'local' 'wild' 'other'; do
local s_base="${c_base}-$WILD_S"
case $WILD_S in local) WILD_S="$T_SYS";; wild) WILD_S="%";; esac
for WILD_H in 'local' 'wild' 'other'; do
local h_base="${s_base}-$WILD_H"
case $WILD_H in local) WILD_H="$T_HOST";; wild) WILD_H="%";; esac
local f="${h_base}##${WILD_C}.${WILD_S}.${WILD_H}"
make_parents "$DIR_WORKTREE/$f"
echo "$f" > "$DIR_WORKTREE/$f"
done
done
done
#; class.system.host.user
for WILD_C in 'local' 'wild' 'other'; do
local c_base="wild-class-system-host-user-$WILD_C"
case $WILD_C in local) WILD_C="set_class";; wild) WILD_C="%";; esac
for WILD_S in 'local' 'wild' 'other'; do
local s_base="${c_base}-$WILD_S"
case $WILD_S in local) WILD_S="$T_SYS";; wild) WILD_S="%";; esac
for WILD_H in 'local' 'wild' 'other'; do
local h_base="${s_base}-$WILD_H"
case $WILD_H in local) WILD_H="$T_HOST";; wild) WILD_H="%";; esac
for WILD_U in 'local' 'wild' 'other'; do
local u_base="${h_base}-$WILD_U"
case $WILD_U in local) WILD_U="$T_USER";; wild) WILD_U="%";; esac
local f="${u_base}##${WILD_C}.${WILD_S}.${WILD_H}.${WILD_U}"
make_parents "$DIR_WORKTREE/$f"
echo "$f" > "$DIR_WORKTREE/$f"
done
done
done
done
fi
for f in \
.bash_profile \
.gnupg/gpg.conf \
.gnupg/pubring.gpg \
.gnupg/secring.gpg \
.hammerspoon/init.lua \
.ssh/config \
.ssh/secret.key \
.ssh/secret.pub \
.tmux.conf \
.vimrc \
;
do
make_parents "$DIR_WORKTREE/$f"
echo "$f" > "$DIR_WORKTREE/$f"
done
#; change all perms (so permission updates can be observed)
find "$DIR_WORKTREE" -exec chmod 0777 '{}' ';'