1
0
mirror of https://github.com/TheLocehiliosan/yadm synced 2026-03-02 03:49:29 +00:00

Support YADM_DISTRO in Jinja templates (#68)

This commit is contained in:
Tim Byrne
2017-07-03 16:21:27 -05:00
parent 280b1179f7
commit 5293db986a
4 changed files with 64 additions and 3 deletions

View File

@@ -0,0 +1,49 @@
load common
load_fixtures
@test "Query distro (lsb_release present)" {
echo "
Use value of lsb_release -si
"
#shellcheck source=/dev/null
YADM_TEST=1 source "$T_YADM"
status=0
{ output=$( query_distro ); } || {
status=$?
true
}
expected="${T_DISTRO}"
echo "output=$output"
echo "expect=$expected"
[ "$status" == 0 ]
[ "$output" = "$expected" ]
}
@test "Query distro (lsb_release missing)" {
echo "
Empty value if lsb_release is missing
"
#shellcheck source=/dev/null
YADM_TEST=1 source "$T_YADM"
LSB_RELEASE_PROGRAM="missing_lsb_release"
echo "Using $LSB_RELEASE_PROGRAM as lsb_release"
status=0
{ output=$( query_distro ); } || {
status=$?
true
}
expected=""
echo "output=$output"
echo "expect=$expected"
[ "$status" == 0 ]
[ "$output" = "$expected" ]
}

View File

@@ -21,11 +21,11 @@ function test_alt() {
case $alt_type in
base)
real_name="alt-jinja"
file_content_match="-${T_SYS}-${T_HOST}-${T_USER}"
file_content_match="-${T_SYS}-${T_HOST}-${T_USER}-${T_DISTRO}"
;;
override_all)
real_name="alt-jinja"
file_content_match="custom_class-custom_system-custom_host-custom_user"
file_content_match="custom_class-custom_system-custom_host-custom_user-${T_DISTRO}"
;;
esac

View File

@@ -27,6 +27,8 @@ function load_fixtures() {
T_HOST=$(hostname -s)
export T_USER
T_USER=$(id -u -n)
export T_DISTRO
T_DISTRO=$(lsb_release -si 2>/dev/null || true)
}
function configure_git() {
@@ -202,7 +204,7 @@ function create_worktree() {
make_parents "$DIR_WORKTREE/$f"
echo "$f" > "$DIR_WORKTREE/$f"
done
echo "{{ YADM_CLASS }}-{{ YADM_OS }}-{{ YADM_HOSTNAME }}-{{ YADM_USER }}" > "$DIR_WORKTREE/alt-jinja##yadm.j2"
echo "{{ YADM_CLASS }}-{{ YADM_OS }}-{{ YADM_HOSTNAME }}-{{ YADM_USER }}-{{ YADM_DISTRO }}" > "$DIR_WORKTREE/alt-jinja##yadm.j2"
fi
#; for some cygwin tests