Skip to content

Commit

Permalink
Add get_3rd_parties_versions & update print_usage
Browse files Browse the repository at this point in the history
  • Loading branch information
danie1k committed Apr 16, 2022
1 parent 73acd8c commit b89bd69
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 4 deletions.
25 changes: 22 additions & 3 deletions src/rsync_offsite_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,15 @@ function check_prerequisites() {
done
}


function print_usage() {
_out "Usage: ${SELF} [OPTIONS]"
_header "$(basename "${SELF}") v${__VERSION__}" \
"Usage: ${SELF} [OPTIONS]" \
'' \
"dasel: ${DASEL_VER:?}" \
"envsubst: ${ENVSUBST_VER:?}" \
"rsync: ${RSYNC_VER:?} (protocol version ${RSYNC_PROTOCOL_VER:?})" \
"yq: ${YQ_VER:?}"

_out
_out "Options:"
_out " -c FILE Path to config file for this job"
Expand All @@ -269,7 +275,6 @@ function print_usage() {
_out " -n NAME Custom name of the job"
_out " -h Shows this help"
_out
_out "Version ${__VERSION__}"
}

function collect_options() {
Expand Down Expand Up @@ -340,6 +345,20 @@ function list_active_jobs() {
fi
}

function get_3rd_parties_versions() {
DASEL_VER="$(_get_version dasel)"
ENVSUBST_VER="$(_get_version envsubst)"
RSYNC_PROTOCOL_VER="$(_get_version rsync)"
RSYNC_VER="$(_get_version rsync 3)"
YQ_VER="$(_get_version yq)"

export DASEL_VER
export ENVSUBST_VER
export RSYNC_PROTOCOL_VER
export RSYNC_VER
export YQ_VER
}

return 0 # FIXME: Remove

#
Expand Down
16 changes: 16 additions & 0 deletions test/test_collect_options.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,26 @@
setup() {
load 'test_helper/common-setup'
_common_setup

unset CONFIG_FILE
unset DRY_RUN_FLAG
unset JOB_NAME
unset LIST_ONLY_FLAG

# 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 "collect_options should print usage when no args given" {
Expand Down
31 changes: 31 additions & 0 deletions test/test_get_3rd_parties_versions.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bats

setup() {
load 'test_helper/common-setup'
_common_setup

unset DASEL_VER
unset ENVSUBST_VER
unset RSYNC_PROTOCOL_VER
unset RSYNC_VER
unset YQ_VER
}

@test "get_3rd_parties_versions" {
# MOCK
dasel() { echo 'lorem ipsum 42'; }
envsubst() { echo 'lorem ipsum 42'; }
rsync() { echo 'lorem ipsum foo bar 42'; }
yq() { echo 'lorem ipsum 42'; }

# WHEN
get_3rd_parties_versions

# THEN
assert_equal $? 0
assert_equal "${DASEL_VER:?}" '42'
assert_equal "${ENVSUBST_VER:?}" '42'
assert_equal "${RSYNC_PROTOCOL_VER:?}" '42'
assert_equal "${RSYNC_VER:?}" 'foo'
assert_equal "${YQ_VER:?}" '42'
}
20 changes: 19 additions & 1 deletion test/test_print_usage.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
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" {
Expand All @@ -13,5 +28,8 @@ setup() {
assert_success
assert_output --partial 'Usage:'
assert_output --partial 'Options:'
assert_output --partial 'Version'
assert_output --partial 'dasel:'
assert_output --partial 'envsubst:'
assert_output --partial 'rsync:'
assert_output --partial 'yq:'
}

0 comments on commit b89bd69

Please sign in to comment.