diff --git a/src/rsync_offsite_backup.sh b/src/rsync_offsite_backup.sh index 6d1191c..97ae1f7 100755 --- a/src/rsync_offsite_backup.sh +++ b/src/rsync_offsite_backup.sh @@ -442,8 +442,18 @@ function collect_rsync_options() { export RSYNC_OPTIONS } -return 0 # FIXME: Remove +function print_nice_header() { + local _dry_run="$([[ ${DRY_RUN_FLAG} -eq 1 ]] && echo 'yes' || echo 'no')" + local _remote_target="${SSH_USER}@${SSH_HOST}:${PATH_REMOTE}" + + _header "STARTING RSYNC SESSION" \ + "Job name: ${JOB_NAME}" \ + "Dry run: ${_dry_run}" \ + "Local source: ${PATH_SOURCE}" \ + "Remote target: ${_remote_target}" +} +return 0 # FIXME: Remove # # Finally, tell rsync about paths to transfer @@ -453,24 +463,6 @@ RSYNC_OPTIONS+=( "${SSH_USER}@${SSH_HOST}:$(printf '%q' "${PATH_REMOTE}")" ) - -# -# Print nice header -# -_printf_line=' ' -# shellcheck disable=SC2250 -_dry_run="$([[ $DRY_RUN_FLAG -eq 1 ]] && echo 'yes' || echo 'no')" -_remote_target="${SSH_USER}@${SSH_HOST}:${PATH_REMOTE}" -echo "┌────────────────────────────────────────────────────────────────────────────┐" -echo "│ STARTING RSYNC SESSION │" -echo "├────────────────────────────────────────────────────────────────────────────┤" -printf "│ Job name: %s%s│\n" "${JOB_NAME}" "${_printf_line:${#JOB_NAME}}" -printf "│ Dry run: %s%s│\n" "${_dry_run}" "${_printf_line:${#_dry_run}}" -printf "│ Local source: %s%s│\n" "${PATH_SOURCE}" "${_printf_line:${#PATH_SOURCE}}" -printf "│ Remote target: %s%s│\n" "${_remote_target}" "${_printf_line:${#_remote_target}}" -echo "└────────────────────────────────────────────────────────────────────────────┘" - - # # Dry run message # diff --git a/test/test_print_.bats b/test/test_print_.bats new file mode 100644 index 0000000..0db6796 --- /dev/null +++ b/test/test_print_.bats @@ -0,0 +1,84 @@ +#!/usr/bin/env bats + +setup() { + load 'test_helper/common-setup' + _common_setup + + # MOCK / GIVEN + export DASEL_VER='42' + export ENVSUBST_VER='42' + export RSYNC_PROTOCOL_VER='42' + export RSYNC_VER='42' + export YQ_VER='42' + + export SSH_USER='foo' + export SSH_HOST='bar' + export PATH_REMOTE='lorem/' + export JOB_NAME='ipsum' + export PATH_SOURCE='/given/path/' +} + +teardown() { + unset DASEL_VER + unset ENVSUBST_VER + unset RSYNC_PROTOCOL_VER + unset RSYNC_VER + unset YQ_VER + + unset DRY_RUN_FLAG + unset JOB_NAME + unset PATH_REMOTE + unset PATH_SOURCE + unset SSH_HOST + unset SSH_USER +} + +# print_usage ------------------------------------------------------------------ + +@test "print_usage result" { + # WHEN + run print_usage + + # THEN + assert_success + assert_output --partial 'Usage:' + assert_output --partial 'Options:' + assert_output --partial 'dasel:' + assert_output --partial 'envsubst:' + assert_output --partial 'rsync:' + assert_output --partial 'yq:' +} + +# print_nice_header ------------------------------------------------------------ + +@test "print_nice_header : when dry run is disabled" { + # GIVEN + export DRY_RUN_FLAG=0 + + # WHEN + run print_nice_header + + # THEN + assert_success + assert_output --partial 'STARTING RSYNC SESSION' + assert_output --partial 'Job name: ipsum' + assert_output --partial 'Dry run: no' + assert_output --partial 'Local source: /given/path/' + assert_output --partial 'Remote target: foo@bar:lorem/' +} + +@test "print_nice_header : when dry run is enabled" { + # GIVEN + export DRY_RUN_FLAG=1 + + # WHEN + run print_nice_header + + # THEN + assert_success + assert_output --partial 'STARTING RSYNC SESSION' + assert_output --partial 'Job name: ipsum' + assert_output --partial 'Dry run: yes' + assert_output --partial 'Local source: /given/path/' + assert_output --partial 'Remote target: foo@bar:lorem/' +} diff --git a/test/test_print_usage.bats b/test/test_print_usage.bats deleted file mode 100644 index 7214b89..0000000 --- a/test/test_print_usage.bats +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bats - -setup() { - load 'test_helper/common-setup' - _common_setup - - # MOCK - export DASEL_VER='42' - export ENVSUBST_VER='42' - export RSYNC_PROTOCOL_VER='42' - export RSYNC_VER='42' - export YQ_VER='42' -} - -teardown() { - unset DASEL_VER - unset ENVSUBST_VER - unset RSYNC_PROTOCOL_VER - unset RSYNC_VER - unset YQ_VER -} - -@test "print_usage result" { - # WHEN - run print_usage - - # THEN - assert_success - assert_output --partial 'Usage:' - assert_output --partial 'Options:' - assert_output --partial 'dasel:' - assert_output --partial 'envsubst:' - assert_output --partial 'rsync:' - assert_output --partial 'yq:' -}