From 3ea710317a0e32c569d7eca7fa4435ab53489876 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Wed, 18 Jan 2017 01:06:51 -0600 Subject: [PATCH] Add acceptance tests for alt-link wildcards (#43) --- test/111_accept_wildcard_alt.bats | 114 ++++++++++++++++++++++++++++++ test/common.bash | 43 +++++++++++ 2 files changed, 157 insertions(+) create mode 100644 test/111_accept_wildcard_alt.bats diff --git a/test/111_accept_wildcard_alt.bats b/test/111_accept_wildcard_alt.bats new file mode 100644 index 0000000..a613e2d --- /dev/null +++ b/test/111_accept_wildcard_alt.bats @@ -0,0 +1,114 @@ +load common +load_fixtures +status=;output=; #; populated by bats run() + +IN_REPO=(wild*) + +setup() { + destroy_tmp + build_repo "${IN_REPO[@]}" +} + +function test_alt() { + local link_name="$1" + local link_match="$2" + + #; run yadm alt + run "${T_YADM_Y[@]}" alt + #; validate status and output + if [ "$status" != 0 ] || [[ ! "$output" =~ Linking.+$link_name ]]; then + echo "OUTPUT:$output" + echo "ERROR: Could not confirm status and output of alt command" + return 1; + fi + + #; correct link should be present + local link_content + link_content=$(cat "$T_DIR_WORK/$link_name") + if [ "$link_content" != "$link_match" ]; then + echo "OUTPUT:$output" + echo "ERROR: Link content is not correct" + return 1 + fi +} + +@test "Command 'alt' (wild none)" { + echo " + When the command 'alt' is provided + and file matches only ## + Report the linking + Verify correct file is linked + Exit with 0 + " + + test_alt 'wild-none' 'wild-none##' +} + +@test "Command 'alt' (wild system)" { + echo " + When the command 'alt' is provided + and file matches only ##SYSTEM + with possible wildcards + Report the linking + Verify correct file is linked + Exit with 0 + " + + for WILD_S in 'local' 'wild'; do + local s_base="wild-system-$WILD_S" + case $WILD_S in local) WILD_S="$T_SYS";; wild) WILD_S="%";; esac + local match="${s_base}##${WILD_S}" + echo test_alt "$s_base" "$match" + test_alt "$s_base" "$match" + done +} + +@test "Command 'alt' (wild host)" { + echo " + When the command 'alt' is provided + and file matches only ##SYSTEM.HOST + with possible wildcards + Report the linking + Verify correct file is linked + Exit with 0 + " + + for WILD_S in 'local' 'wild'; do + local s_base="wild-host-$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_S}.${WILD_H}" + echo test_alt "$h_base" "$match" + test_alt "$h_base" "$match" + done + done +} + +@test "Command 'alt' (wild user)" { + echo " + When the command 'alt' is provided + and file matches only ##SYSTEM.HOST.USER + with possible wildcards + Report the linking + Verify correct file is linked + Exit with 0 + " + + for WILD_S in 'local' 'wild'; do + local s_base="wild-user-$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_S}.${WILD_H}.${WILD_U}" + echo test_alt "$u_base" "$match" + test_alt "$u_base" "$match" + done + done + done +} diff --git a/test/common.bash b/test/common.bash index 3d44193..65a3610 100644 --- a/test/common.bash +++ b/test/common.bash @@ -171,6 +171,49 @@ function create_worktree() { echo "$f" > "$DIR_WORKTREE/$f" done + #; wildcard test data - yes this is a big mess :( + #; none + for f in "wild-none##"; do + make_parents "$DIR_WORKTREE/$f" + echo "$f" > "$DIR_WORKTREE/$f" + done + #; system + for WILD_S in 'local' 'wild' 'other'; do + local s_base="wild-system-$WILD_S" + case $WILD_S in local) WILD_S="$T_SYS";; wild) WILD_S="%";; esac + local f="${s_base}##${WILD_S}" + make_parents "$DIR_WORKTREE/$f" + echo "$f" > "$DIR_WORKTREE/$f" + done + #; system.host + for WILD_S in 'local' 'wild' 'other'; do + local s_base="wild-host-$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_S}.${WILD_H}" + make_parents "$DIR_WORKTREE/$f" + echo "$f" > "$DIR_WORKTREE/$f" + done + done + #; system.host.user + for WILD_S in 'local' 'wild' 'other'; do + local s_base="wild-user-$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_S}.${WILD_H}.${WILD_U}" + make_parents "$DIR_WORKTREE/$f" + echo "$f" > "$DIR_WORKTREE/$f" + done + done + done + #; change all perms (so permission updates can be observed) find "$DIR_WORKTREE" -exec chmod 0777 '{}' ';'