|
|
|
@ -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' '' |
|
|
|
|
} |
|
|
|
|