2016-03-23 20:18:33 -04:00
|
|
|
load common
|
|
|
|
load_fixtures
|
2016-04-06 13:33:42 -04:00
|
|
|
status=;output=; #; populated by bats run()
|
2016-03-23 20:18:33 -04:00
|
|
|
|
2017-01-06 08:50:36 -05:00
|
|
|
IN_REPO=(alt* "dir one")
|
2016-03-23 20:18:33 -04:00
|
|
|
|
2017-01-07 16:38:21 -05:00
|
|
|
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
|
|
|
|
echo "$efile" >> "$T_YADM_ENCRYPT"
|
|
|
|
echo "$efile" >> "$T_DIR_WORK/$efile"
|
|
|
|
mkdir -p "$T_DIR_WORK/dir one/$efile"
|
|
|
|
echo "dir one/$efile/file1" >> "$T_YADM_ENCRYPT"
|
|
|
|
echo "dir one/$efile/file1" >> "$T_DIR_WORK/dir one/$efile/file1"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2016-03-23 20:18:33 -04:00
|
|
|
setup() {
|
|
|
|
destroy_tmp
|
|
|
|
build_repo "${IN_REPO[@]}"
|
2017-01-07 16:38:21 -05:00
|
|
|
create_encrypt
|
2016-03-23 20:18:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_alt() {
|
|
|
|
local alt_type="$1"
|
2016-08-05 18:03:17 -04:00
|
|
|
local test_overwrite="$2"
|
|
|
|
local auto_alt="$3"
|
2016-03-23 20:18:33 -04:00
|
|
|
|
|
|
|
#; detemine test parameters
|
|
|
|
case $alt_type in
|
|
|
|
base)
|
|
|
|
link_name="alt-base"
|
|
|
|
link_match="$link_name##"
|
|
|
|
;;
|
|
|
|
system)
|
|
|
|
link_name="alt-system"
|
|
|
|
link_match="$link_name##$T_SYS"
|
|
|
|
;;
|
|
|
|
host)
|
|
|
|
link_name="alt-host"
|
|
|
|
link_match="$link_name##$T_SYS.$T_HOST"
|
|
|
|
;;
|
|
|
|
user)
|
|
|
|
link_name="alt-user"
|
|
|
|
link_match="$link_name##$T_SYS.$T_HOST.$T_USER"
|
|
|
|
;;
|
2017-01-07 16:38:21 -05:00
|
|
|
encrypted_base)
|
|
|
|
link_name="encrypted-base"
|
|
|
|
link_match="$link_name##"
|
|
|
|
;;
|
|
|
|
encrypted_system)
|
|
|
|
link_name="encrypted-system"
|
|
|
|
link_match="$link_name##$T_SYS"
|
|
|
|
;;
|
|
|
|
encrypted_host)
|
|
|
|
link_name="encrypted-host"
|
|
|
|
link_match="$link_name##$T_SYS.$T_HOST"
|
|
|
|
;;
|
|
|
|
encrypted_user)
|
|
|
|
link_name="encrypted-user"
|
|
|
|
link_match="$link_name##$T_SYS.$T_HOST.$T_USER"
|
|
|
|
;;
|
2017-01-18 20:51:13 -05:00
|
|
|
override_system)
|
|
|
|
link_name="alt-override-system"
|
|
|
|
link_match="$link_name##custom_system"
|
|
|
|
;;
|
|
|
|
override_host)
|
|
|
|
link_name="alt-override-host"
|
|
|
|
link_match="$link_name##$T_SYS.custom_host"
|
|
|
|
;;
|
|
|
|
override_user)
|
|
|
|
link_name="alt-override-user"
|
|
|
|
link_match="$link_name##$T_SYS.$T_HOST.custom_user"
|
|
|
|
;;
|
2016-03-23 20:18:33 -04:00
|
|
|
esac
|
2017-01-06 08:50:36 -05:00
|
|
|
dir_link_name="dir one/${link_name}"
|
|
|
|
dir_link_match="dir one/${link_match}"
|
2016-03-23 20:18:33 -04:00
|
|
|
|
2016-08-05 18:03:17 -04:00
|
|
|
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
|
2016-03-23 20:18:33 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
#; configure yadm.auto_alt=false
|
|
|
|
if [ "$auto_alt" = "false" ]; then
|
|
|
|
git config --file="$T_YADM_CONFIG" yadm.auto-alt false
|
|
|
|
fi
|
|
|
|
|
|
|
|
#; run yadm (alt or status)
|
|
|
|
if [ -z "$auto_alt" ]; then
|
2016-04-06 13:33:42 -04:00
|
|
|
run "${T_YADM_Y[@]}" alt
|
2016-03-23 20:18:33 -04:00
|
|
|
#; validate status and output
|
2016-08-05 18:03:17 -04:00
|
|
|
if [ "$status" != 0 ] || [[ ! "$output" =~ Linking.+$link_name ]] || [[ ! "$output" =~ Linking.+$dir_link_name ]]; then
|
|
|
|
echo "OUTPUT:$output"
|
2016-03-23 20:18:33 -04:00
|
|
|
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
|
2016-04-06 13:33:42 -04:00
|
|
|
run "${T_YADM_Y[@]}" status
|
2016-08-05 18:03:17 -04:00
|
|
|
if [ -n "$auto_alt" ] && [[ "$output" =~ Linking.+$link_name ]] && [[ "$output" =~ Linking.+$dir_link_name ]]; then
|
2016-03-23 20:18:33 -04:00
|
|
|
echo "ERROR: Reporting of link should not happen"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
#; validate link content
|
2017-01-07 16:38:21 -05:00
|
|
|
if [[ "$alt_type" =~ none ]] || [ "$auto_alt" = "false" ]; then
|
2016-03-23 20:18:33 -04:00
|
|
|
#; no link should be present
|
2016-08-05 18:03:17 -04:00
|
|
|
if [ -L "$T_DIR_WORK/$link_name" ] || [ -L "$T_DIR_WORK/$dir_link_name" ]; then
|
|
|
|
echo "ERROR: Links should not exist"
|
2016-03-23 20:18:33 -04:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
#; correct link should be present
|
2016-04-06 13:33:42 -04:00
|
|
|
local link_content
|
2016-08-05 18:03:17 -04:00
|
|
|
local dir_link_content
|
2016-04-06 13:33:42 -04:00
|
|
|
link_content=$(cat "$T_DIR_WORK/$link_name")
|
2016-08-05 18:03:17 -04:00
|
|
|
dir_link_content=$(cat "$T_DIR_WORK/$dir_link_name/file1")
|
|
|
|
if [ "$link_content" != "$link_match" ] || [ "$dir_link_content" != "$dir_link_match/file1" ]; then
|
2017-01-18 20:51:13 -05:00
|
|
|
echo "link_content: $link_content"
|
|
|
|
echo "dir_link_content: $dir_link_content"
|
2016-03-23 20:18:33 -04:00
|
|
|
echo "ERROR: Link content is not correct"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'alt' (select base)" {
|
|
|
|
echo "
|
|
|
|
When the command 'alt' is provided
|
|
|
|
and file matches only ##
|
|
|
|
Report the linking
|
|
|
|
Verify correct file is linked
|
|
|
|
Exit with 0
|
|
|
|
"
|
|
|
|
|
2016-08-05 18:03:17 -04:00
|
|
|
test_alt 'base' 'false' ''
|
2016-03-23 20:18:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'alt' (select system)" {
|
|
|
|
echo "
|
|
|
|
When the command 'alt' is provided
|
|
|
|
and file matches only ##SYSTEM
|
|
|
|
Report the linking
|
|
|
|
Verify correct file is linked
|
|
|
|
Exit with 0
|
|
|
|
"
|
|
|
|
|
2016-08-05 18:03:17 -04:00
|
|
|
test_alt 'system' 'false' ''
|
2016-03-23 20:18:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'alt' (select host)" {
|
|
|
|
echo "
|
|
|
|
When the command 'alt' is provided
|
|
|
|
and file matches only ##SYSTEM.HOST
|
|
|
|
Report the linking
|
|
|
|
Verify correct file is linked
|
|
|
|
Exit with 0
|
|
|
|
"
|
|
|
|
|
2016-08-05 18:03:17 -04:00
|
|
|
test_alt 'host' 'false' ''
|
2016-03-23 20:18:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'alt' (select user)" {
|
|
|
|
echo "
|
|
|
|
When the command 'alt' is provided
|
|
|
|
and file matches only ##SYSTEM.HOST.USER
|
|
|
|
Report the linking
|
|
|
|
Verify correct file is linked
|
|
|
|
Exit with 0
|
|
|
|
"
|
|
|
|
|
2016-08-05 18:03:17 -04:00
|
|
|
test_alt 'user' 'false' ''
|
2016-03-23 20:18:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'alt' (select none)" {
|
|
|
|
echo "
|
|
|
|
When the command 'alt' is provided
|
|
|
|
and no file matches
|
|
|
|
Verify there is no link
|
|
|
|
Exit with 0
|
|
|
|
"
|
|
|
|
|
2016-08-05 18:03:17 -04:00
|
|
|
test_alt 'none' 'false' ''
|
2016-03-23 20:18:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'auto-alt' (enabled)" {
|
|
|
|
echo "
|
|
|
|
When a command possibly changes the repo
|
|
|
|
and auto-alt is configured true
|
|
|
|
automatically process alternates
|
|
|
|
report no linking (not loud)
|
|
|
|
verify alternate created
|
|
|
|
"
|
|
|
|
|
2016-08-05 18:03:17 -04:00
|
|
|
test_alt 'base' 'false' 'true'
|
2016-03-23 20:18:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'auto-alt' (disabled)" {
|
|
|
|
echo "
|
|
|
|
When a command possibly changes the repo
|
|
|
|
and auto-alt is configured false
|
|
|
|
do no linking
|
|
|
|
verify no links
|
|
|
|
"
|
|
|
|
|
2016-08-05 18:03:17 -04:00
|
|
|
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' ''
|
2016-03-23 20:18:33 -04:00
|
|
|
}
|
2017-01-07 16:38:21 -05:00
|
|
|
|
|
|
|
@test "Command 'alt' (select encrypted base)" {
|
|
|
|
echo "
|
|
|
|
When the command 'alt' is provided
|
|
|
|
and encrypted file matches only ##
|
|
|
|
Report the linking
|
|
|
|
Verify correct encrypted file is linked
|
|
|
|
Exit with 0
|
|
|
|
"
|
|
|
|
|
|
|
|
test_alt 'encrypted_base' 'false' ''
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'alt' (select encrypted system)" {
|
|
|
|
echo "
|
|
|
|
When the command 'alt' is provided
|
|
|
|
and encrypted file matches only ##SYSTEM
|
|
|
|
Report the linking
|
|
|
|
Verify correct encrypted file is linked
|
|
|
|
Exit with 0
|
|
|
|
"
|
|
|
|
|
|
|
|
test_alt 'encrypted_system' 'false' ''
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'alt' (select encrypted host)" {
|
|
|
|
echo "
|
|
|
|
When the command 'alt' is provided
|
|
|
|
and encrypted file matches only ##SYSTEM.HOST
|
|
|
|
Report the linking
|
|
|
|
Verify correct encrypted file is linked
|
|
|
|
Exit with 0
|
|
|
|
"
|
|
|
|
|
|
|
|
test_alt 'encrypted_host' 'false' ''
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'alt' (select encrypted user)" {
|
|
|
|
echo "
|
|
|
|
When the command 'alt' is provided
|
|
|
|
and encrypted file matches only ##SYSTEM.HOST.USER
|
|
|
|
Report the linking
|
|
|
|
Verify correct encrypted file is linked
|
|
|
|
Exit with 0
|
|
|
|
"
|
|
|
|
|
|
|
|
test_alt 'encrypted_user' 'false' ''
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'alt' (select encrypted none)" {
|
|
|
|
echo "
|
|
|
|
When the command 'alt' is provided
|
|
|
|
and no encrypted file matches
|
|
|
|
Verify there is no link
|
|
|
|
Exit with 0
|
|
|
|
"
|
|
|
|
|
|
|
|
test_alt 'encrypted_none' 'false' ''
|
|
|
|
}
|
2017-01-18 20:51:13 -05:00
|
|
|
|
|
|
|
@test "Command 'alt' (override-system)" {
|
|
|
|
echo "
|
|
|
|
When the command 'alt' is provided
|
|
|
|
and file matches only ##SYSTEM
|
|
|
|
after setting alt.os
|
|
|
|
Report the linking
|
|
|
|
Verify correct file is linked
|
|
|
|
Exit with 0
|
|
|
|
"
|
|
|
|
|
|
|
|
git config --file="$T_YADM_CONFIG" alt.os custom_system
|
|
|
|
test_alt 'override_system' 'false' ''
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'alt' (override-host)" {
|
|
|
|
echo "
|
|
|
|
When the command 'alt' is provided
|
|
|
|
and file matches only ##SYSTEM.HOST
|
|
|
|
after setting alt.host
|
|
|
|
Report the linking
|
|
|
|
Verify correct file is linked
|
|
|
|
Exit with 0
|
|
|
|
"
|
|
|
|
|
|
|
|
git config --file="$T_YADM_CONFIG" alt.host custom_host
|
|
|
|
test_alt 'override_host' 'false' ''
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "Command 'alt' (override-user)" {
|
|
|
|
echo "
|
|
|
|
When the command 'alt' is provided
|
|
|
|
and file matches only ##SYSTEM.HOST.USER
|
|
|
|
after setting alt.user
|
|
|
|
Report the linking
|
|
|
|
Verify correct file is linked
|
|
|
|
Exit with 0
|
|
|
|
"
|
|
|
|
|
|
|
|
git config --file="$T_YADM_CONFIG" alt.user custom_user
|
|
|
|
test_alt 'override_user' 'false' ''
|
|
|
|
}
|