diff --git a/test/108_accept_alt.bats b/test/108_accept_alt.bats index 19997d0..ffa29c5 100644 --- a/test/108_accept_alt.bats +++ b/test/108_accept_alt.bats @@ -2,7 +2,7 @@ load common load_fixtures status=;output=; #; populated by bats run() -IN_REPO=(alt*) +IN_REPO=(alt* dir1) setup() { destroy_tmp @@ -11,7 +11,8 @@ setup() { function test_alt() { local alt_type="$1" - local auto_alt="$2" + local test_overwrite="$2" + local auto_alt="$3" #; detemine test parameters case $alt_type in @@ -32,11 +33,19 @@ function test_alt() { link_match="$link_name##$T_SYS.$T_HOST.$T_USER" ;; esac + dir_link_name="dir1/${link_name}" + dir_link_match="dir1/${link_match}" - #; verify link doesn't already exist - if [ -L "$T_DIR_WORK/$link_name" ]; then - echo "ERROR: Link already exists before running yadm" - return 1 + if [ "$test_overwrite" = "true" ]; then + #; create incorrect links (to overwrite) + ln -nfs "$T_DIR_WORK/dir2/file2" "$T_DIR_WORK/$link_name" + ln -nfs "$T_DIR_WORK/dir2" "$T_DIR_WORK/$dir_link_name" + else + #; verify link doesn't already exist + if [ -L "$T_DIR_WORK/$link_name" ] || [ -L "$T_DIR_WORK/$dir_link_name" ]; then + echo "ERROR: Link already exists before running yadm" + return 1 + fi fi #; configure yadm.auto_alt=false @@ -48,14 +57,15 @@ function test_alt() { if [ -z "$auto_alt" ]; then run "${T_YADM_Y[@]}" alt #; validate status and output - if [ "$status" != 0 ] || [[ ! "$output" =~ Linking.+$link_name ]]; then + if [ "$status" != 0 ] || [[ ! "$output" =~ Linking.+$link_name ]] || [[ ! "$output" =~ Linking.+$dir_link_name ]]; then + echo "OUTPUT:$output" echo "ERROR: Could not confirm status and output of alt command" return 1; fi else #; running any passed through Git command should trigger auto-alt run "${T_YADM_Y[@]}" status - if [ -n "$auto_alt" ] && [[ "$output" =~ Linking.+$link_name ]]; then + if [ -n "$auto_alt" ] && [[ "$output" =~ Linking.+$link_name ]] && [[ "$output" =~ Linking.+$dir_link_name ]]; then echo "ERROR: Reporting of link should not happen" return 1 fi @@ -64,15 +74,17 @@ function test_alt() { #; validate link content if [ "$alt_type" = "none" ] || [ "$auto_alt" = "false" ]; then #; no link should be present - if [ -L "$T_DIR_WORK/$link_name" ]; then - echo "ERROR: Link should not exist" + if [ -L "$T_DIR_WORK/$link_name" ] || [ -L "$T_DIR_WORK/$dir_link_name" ]; then + echo "ERROR: Links should not exist" return 1 fi else #; correct link should be present local link_content + local dir_link_content link_content=$(cat "$T_DIR_WORK/$link_name") - if [ "$link_content" != "$link_match" ]; then + dir_link_content=$(cat "$T_DIR_WORK/$dir_link_name/file1") + if [ "$link_content" != "$link_match" ] || [ "$dir_link_content" != "$dir_link_match/file1" ]; then echo "ERROR: Link content is not correct" return 1 fi @@ -88,7 +100,7 @@ function test_alt() { Exit with 0 " - test_alt 'base' "" + test_alt 'base' 'false' '' } @test "Command 'alt' (select system)" { @@ -100,7 +112,7 @@ function test_alt() { Exit with 0 " - test_alt 'system' "" + test_alt 'system' 'false' '' } @test "Command 'alt' (select host)" { @@ -112,7 +124,7 @@ function test_alt() { Exit with 0 " - test_alt 'host' "" + test_alt 'host' 'false' '' } @test "Command 'alt' (select user)" { @@ -124,7 +136,7 @@ function test_alt() { Exit with 0 " - test_alt 'user' "" + test_alt 'user' 'false' '' } @test "Command 'alt' (select none)" { @@ -135,7 +147,7 @@ function test_alt() { Exit with 0 " - test_alt 'none' "" + test_alt 'none' 'false' '' } @test "Command 'auto-alt' (enabled)" { @@ -147,7 +159,7 @@ function test_alt() { verify alternate created " - test_alt 'base' "true" + test_alt 'base' 'false' 'true' } @test "Command 'auto-alt' (disabled)" { @@ -158,5 +170,17 @@ function test_alt() { verify no links " - test_alt 'base' "false" + test_alt 'base' 'false' 'false' +} + +@test "Command 'alt' (overwrite existing link)" { + echo " + When the command 'alt' is provided + and the link exists, and is wrong + Report the linking + Verify correct file is linked + Exit with 0 + " + + test_alt 'base' 'true' '' } diff --git a/test/common.bash b/test/common.bash index 0a5eb86..70993ac 100644 --- a/test/common.bash +++ b/test/common.bash @@ -104,6 +104,51 @@ function create_worktree() { "alt-user##S.H" \ "alt-user##S.H.U" \ "alt-user##$T_SYS.$T_HOST.$T_USER" \ + "dir1/alt-none##S/file1" \ + "dir1/alt-none##S/file2" \ + "dir1/alt-none##S.H/file1" \ + "dir1/alt-none##S.H/file2" \ + "dir1/alt-none##S.H.U/file1" \ + "dir1/alt-none##S.H.U/file2" \ + "dir1/alt-base##/file1" \ + "dir1/alt-base##/file2" \ + "dir1/alt-base##S/file1" \ + "dir1/alt-base##S/file2" \ + "dir1/alt-base##S.H/file1" \ + "dir1/alt-base##S.H/file2" \ + "dir1/alt-base##S.H.U/file1" \ + "dir1/alt-base##S.H.U/file2" \ + "dir1/alt-system##/file1" \ + "dir1/alt-system##/file2" \ + "dir1/alt-system##S/file1" \ + "dir1/alt-system##S/file2" \ + "dir1/alt-system##S.H/file1" \ + "dir1/alt-system##S.H/file2" \ + "dir1/alt-system##S.H.U/file1" \ + "dir1/alt-system##S.H.U/file2" \ + "dir1/alt-system##$T_SYS/file1" \ + "dir1/alt-system##$T_SYS/file2" \ + "dir1/alt-host##/file1" \ + "dir1/alt-host##/file2" \ + "dir1/alt-host##S/file1" \ + "dir1/alt-host##S/file2" \ + "dir1/alt-host##S.H/file1" \ + "dir1/alt-host##S.H/file2" \ + "dir1/alt-host##S.H.U/file1" \ + "dir1/alt-host##S.H.U/file2" \ + "dir1/alt-host##$T_SYS.$T_HOST/file1" \ + "dir1/alt-host##$T_SYS.$T_HOST/file2" \ + "dir1/alt-user##/file1" \ + "dir1/alt-user##/file2" \ + "dir1/alt-user##S/file1" \ + "dir1/alt-user##S/file2" \ + "dir1/alt-user##S.H/file1" \ + "dir1/alt-user##S.H/file2" \ + "dir1/alt-user##S.H.U/file1" \ + "dir1/alt-user##S.H.U/file2" \ + "dir1/alt-user##$T_SYS.$T_HOST.$T_USER/file1" \ + "dir1/alt-user##$T_SYS.$T_HOST.$T_USER/file2" \ + "dir2/file2" \ .bash_profile \ .gnupg/gpg.conf \ .gnupg/pubring.gpg \