From e4e956fe21f18f3c720763553773a89656246f35 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Sat, 17 Aug 2019 15:20:56 -0500 Subject: [PATCH] Split discovery of alternates test data into a testable function --- test/test_unit_set_local_alt_values.py | 62 ++++++++++++++++++++++++++ yadm | 25 +++++++---- 2 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 test/test_unit_set_local_alt_values.py diff --git a/test/test_unit_set_local_alt_values.py b/test/test_unit_set_local_alt_values.py new file mode 100644 index 0000000..9d34484 --- /dev/null +++ b/test/test_unit_set_local_alt_values.py @@ -0,0 +1,62 @@ +"""Unit tests: set_local_alt_values""" +import pytest +import utils + + +@pytest.mark.parametrize( + 'override', [ + False, + 'class', + 'os', + 'hostname', + 'user', + ], + ids=[ + 'no-override', + 'override-class', + 'override-os', + 'override-hostname', + 'override-user', + ] + ) +@pytest.mark.usefixtures('ds1_copy') +def test_set_local_alt_values( + runner, yadm, paths, tst_sys, tst_host, tst_user, override): + """Use issue_legacy_path_warning""" + script = f""" + YADM_TEST=1 source {yadm} && + set_operating_system && + YADM_DIR={paths.yadm} configure_paths && + set_local_alt_values + echo "class='$local_class'" + echo "os='$local_system'" + echo "host='$local_host'" + echo "user='$local_user'" + """ + + if override: + utils.set_local(paths, override, 'override') + + run = runner(command=['bash'], inp=script) + assert run.success + assert run.err == '' + + if override == 'class': + assert "class='override'" in run.out + else: + assert "class=''" in run.out + + if override == 'os': + assert "os='override'" in run.out + else: + assert f"os='{tst_sys}'" in run.out + + if override == 'hostname': + assert f"host='override'" in run.out + else: + assert f"host='{tst_host}'" in run.out + + if override == 'user': + assert f"user='override'" in run.out + else: + assert f"user='{tst_user}'" in run.out diff --git a/yadm b/yadm index 0918938..badf2d4 100755 --- a/yadm +++ b/yadm @@ -135,34 +135,41 @@ function alt() { require_repo parse_encrypt + # gather values for processing alternates local local_class + local local_system + local local_host + local local_user + set_local_alt_values + + if [ "$YADM_COMPATIBILITY" = "1" ]; then + alt_past + else + alt_future + fi + +} + +function set_local_alt_values() { + local_class="$(config local.class)" - local local_system local_system="$(config local.os)" if [ -z "$local_system" ] ; then local_system="$OPERATING_SYSTEM" fi - local local_host local_host="$(config local.hostname)" if [ -z "$local_host" ] ; then local_host=$(hostname) local_host=${local_host%%.*} # trim any domain from hostname fi - local local_user local_user="$(config local.user)" if [ -z "$local_user" ] ; then local_user=$(id -u -n) fi - if [ "$YADM_COMPATIBILITY" = "1" ]; then - alt_past - else - alt_future - fi - } function alt_future() {