Skip to content

Commit

Permalink
ensure proper sub order and reflect in test
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronhurt committed Aug 31, 2024
1 parent 43cbd08 commit 6b56c30
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
20 changes: 13 additions & 7 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,24 @@ _testZFSReplicate() {

## test config override
(
## likely default values at script load time
ZFS="/sbin/zfs"

Check warning on line 62 in test/test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck

[shellcheck] reported by reviewdog 🐶 Modification of ZFS is local (to subshell caused by (..) group). Raw Output: ./test/test.sh:62:5: info: Modification of ZFS is local (to subshell caused by (..) group). (ShellCheck.SC2030)
SSH="/usr/sbin/ssh"

Check warning on line 63 in test/test.sh

View workflow job for this annotation

GitHub Actions / runner / shellcheck

[shellcheck] reported by reviewdog 🐶 Modification of SSH is local (to subshell caused by (..) group). Raw Output: ./test/test.sh:63:5: info: Modification of SSH is local (to subshell caused by (..) group). (ShellCheck.SC2030)
## source script functions
# shellcheck source=/dev/null
. ../zfs-replicate.sh
printf "_testSetsNoConfig/loadConfigOverrideDefaults\n"
_fail "./ssh.sh %HOST% ./zfs.sh receive -vFd" "$DEST_PIPE_WITH_HOST"
_fail "./zfs.sh receive -vFd" "$DEST_PIPE_WITHOUT_HOST"
_fail "/usr/sbin/ssh %HOST% /sbin/zfs receive -vFd" "$DEST_PIPE_WITH_HOST"
_fail "/sbin/zfs receive -vFd" "$DEST_PIPE_WITHOUT_HOST"
## generate config
config="$(mktemp)"
printf "DEST_PIPE_WITH_HOST=\"pipe with host\"\n" | tee -a "$config"
printf "DEST_PIPE_WITHOUT_HOST=\"pipe without host\"\n" | tee -a "$config"
loadConfig "$config" > /dev/null 2>&1
_fail "pipe with host" "$DEST_PIPE_WITH_HOST"
_fail "pipe without host" "$DEST_PIPE_WITHOUT_HOST"
printf "ZFS=\"myZFS\"\n" >> "$config"
## set SSH via environment
SSH="mySSH"
loadConfig "$config" && rm -f "$config"
## values should match config and environment
_fail "mySSH %HOST% myZFS receive -vFd" "$DEST_PIPE_WITH_HOST"
_fail "myZFS receive -vFd" "$DEST_PIPE_WITHOUT_HOST"
)

## test snapCreate
Expand Down
12 changes: 6 additions & 6 deletions zfs-replicate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ LOGGER="${LOGGER:-$(which logger || true)}"
FIND="${FIND:-$(which find || true)}"
SSH="${SSH:-$(which ssh || true)}"
ZFS="${ZFS:-$(which zfs || true)}"
DEST_PIPE_WITH_HOST="${DEST_PIPE_WITH_HOST:-"$SSH %HOST% $ZFS receive -vFd"}"
DEST_PIPE_WITHOUT_HOST="${DEST_PIPE_WITHOUT_HOST:-"$ZFS receive -vFd"}"
HOST_CHECK="${HOST_CHECK:-"ping -c1 -q -W2 %HOST%"}"

## we default these after config is loaded
DEST_PIPE_WITH_HOST=
DEST_PIPE_WITHOUT_HOST=
## temp path used for lock files
TMPDIR="${TMPDIR:-"/tmp"}"

## init values used in snapCreate and exitClean
__PAIR_COUNT=0
__SKIP_COUNT=0
Expand Down Expand Up @@ -500,10 +499,11 @@ loadConfig() {
readonly FIND
readonly SSH
readonly ZFS
readonly DEST_PIPE_WITH_HOST
readonly DEST_PIPE_WITHOUT_HOST
readonly HOST_CHECK
readonly TMPDIR
## set pipes after configuration to ensure proper $SSH and $ZFS subs
readonly DEST_PIPE_WITH_HOST="${DEST_PIPE_WITH_HOST:-"$SSH %HOST% $ZFS receive -vFd"}"
readonly DEST_PIPE_WITHOUT_HOST="${DEST_PIPE_WITHOUT_HOST:-"$ZFS receive -vFd"}"
## check configuration
if [ -n "$LOG_BASE" ] && [ ! -d "$LOG_BASE" ]; then
mkdir -p "$LOG_BASE"
Expand Down

0 comments on commit 6b56c30

Please sign in to comment.