Skip to content

Commit

Permalink
use FIND setting, add config tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronhurt committed Aug 31, 2024
1 parent 4f1b0e7 commit 43cbd08
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
41 changes: 31 additions & 10 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ SCRIPT_PATH="${0%/*}"

## check line against match and exit on failure
_fail() {
local line=$1 match=$2
line=$1
match=$2
## verbose testing
## hack to match blank lines
if [ "$match" = "null" ] && [ -n "$line" ]; then
printf "FAILED '%s' != ''\n" "$line" && exit 1
Expand All @@ -38,13 +40,12 @@ _testZFSReplicate() {
REPLICATE_SETS="${REPLICATE_SETS} srcPool3/srcFS3@srcHost3:dstPool3/dstFS3"
REPLICATE_SETS="${REPLICATE_SETS} srcPool4/srcFS4@srcHost4:dstPool4/dstFS4@dstHost4"

## source script functions
# shellcheck source=/dev/null
. ../zfs-replicate.sh

## test loadConfig
(
printf "_testSimpleSetNoConfig/loadConfig\n"
## source script functions
# shellcheck source=/dev/null
. ../zfs-replicate.sh
printf "_testSetsNoConfig/loadConfig\n" ## we expect no output and clean exit
loadConfig | awk '{ print NR-1, $0 }' | while read -r idx line; do
printf "%d %s\n" "$idx" "$line"
case $idx in
Expand All @@ -55,10 +56,28 @@ _testZFSReplicate() {
done
)

## test config override
(
## 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"
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"
)

## test snapCreate
(
loadConfig > /dev/null 2>&1
printf "_testSimpleSetNoConfig/snapCreate\n"
## source script functions
# shellcheck source=/dev/null
. ../zfs-replicate.sh && loadConfig
printf "_testSetsNoConfig/snapCreate\n"
snapCreate | awk '{ print NR-1, $0 }' | while read -r idx line; do
match=""
printf "%d %s\n" "$idx" "$line"
Expand Down Expand Up @@ -195,8 +214,10 @@ _testZFSReplicate() {

## test exitClean
(
loadConfig > /dev/null 2>&1
printf "_testSimpleSetNoConfig/exitClean\n"
## source script functions
# shellcheck source=/dev/null
. ../zfs-replicate.sh && loadConfig
printf "_testSetsNoConfig/exitClean\n"
exitClean 0 "test message" | awk '{ print NR-1, $0 }' | while read -r idx line; do
printf "%d %s\n" "$idx" "$line"
case $idx in
Expand Down
2 changes: 1 addition & 1 deletion zfs-replicate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ sortLogs() {
return
fi
## find existing logs
logs=$(find "$LOG_BASE" -maxdepth 1 -type f -name 'autorep-*')
logs=$($FIND "$LOG_BASE" -maxdepth 1 -type f -name 'autorep-*')
## get file change time via stat (platform specific)
if [ "$(uname -s)" = "Linux" ] || [ "$(uname -s)" = "SunOS" ]; then
fstat='stat -c %Z'
Expand Down

0 comments on commit 43cbd08

Please sign in to comment.