From d62e6e0be7902bf9c18df39a74cf44db91bff46e Mon Sep 17 00:00:00 2001 From: Markus Ressel Date: Tue, 29 Mar 2022 04:02:13 +0200 Subject: [PATCH] added folder structure for testing (#7) * added folder structure for testing added testing.sh script added testing github action * delete rebalancing file for testing * run multiple variants of the command * fix "integer expression expected" * added assertions * output logged data --- .github/workflows/shellcheck.yml | 2 +- .github/workflows/test.yml | 19 ++++++++ .gitignore | 5 +- ...\"\302\247$%&()[]{}=?`#'*+-_,;.:|<>~@.txt" | 1 + test/pool/projects/[2020] some project/file | 1 + .../projects/[2020] some project/file.txt | 1 + .../pool/projects/[2020] some project/mp4.txt | 1 + testing.sh | 46 +++++++++++++++++++ zfs-inplace-rebalancing.sh | 2 +- 9 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 "test/pool/abc-123_!\"\302\247$%&()[]{}=?`#'*+-_,;.:|<>~@.txt" create mode 100644 test/pool/projects/[2020] some project/file create mode 100644 test/pool/projects/[2020] some project/file.txt create mode 100644 test/pool/projects/[2020] some project/mp4.txt create mode 100755 testing.sh diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml index 5d1bef1..f62ee85 100644 --- a/.github/workflows/shellcheck.yml +++ b/.github/workflows/shellcheck.yml @@ -15,6 +15,6 @@ jobs: name: Shellcheck runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Run ShellCheck uses: ludeeus/action-shellcheck@master diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..6b1f20f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,19 @@ +# Test + +name: Test + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + shellcheck: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Run testing script + run: ./testing.sh diff --git a/.gitignore b/.gitignore index 4c68dfa..a00bc94 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -rebalance_db.txt \ No newline at end of file +test.log +error.log +rebalance_db.txt +testing_data \ No newline at end of file diff --git "a/test/pool/abc-123_!\"\302\247$%&()[]{}=?`#'*+-_,;.:|<>~@.txt" "b/test/pool/abc-123_!\"\302\247$%&()[]{}=?`#'*+-_,;.:|<>~@.txt" new file mode 100644 index 0000000..30d74d2 --- /dev/null +++ "b/test/pool/abc-123_!\"\302\247$%&()[]{}=?`#'*+-_,;.:|<>~@.txt" @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/test/pool/projects/[2020] some project/file b/test/pool/projects/[2020] some project/file new file mode 100644 index 0000000..30d74d2 --- /dev/null +++ b/test/pool/projects/[2020] some project/file @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/test/pool/projects/[2020] some project/file.txt b/test/pool/projects/[2020] some project/file.txt new file mode 100644 index 0000000..30d74d2 --- /dev/null +++ b/test/pool/projects/[2020] some project/file.txt @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/test/pool/projects/[2020] some project/mp4.txt b/test/pool/projects/[2020] some project/mp4.txt new file mode 100644 index 0000000..30d74d2 --- /dev/null +++ b/test/pool/projects/[2020] some project/mp4.txt @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/testing.sh b/testing.sh new file mode 100755 index 0000000..3c92f2b --- /dev/null +++ b/testing.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# exit script on error +set -e +# exit on undeclared variable +set -u + +log_std_file=./test.log +log_error_file=./error.log +test_data_src=./test/pool +test_pool_data_path=./testing_data + +function prepare() { + # cleanup + rm -f $log_std_file + rm -f $log_error_file + rm -f rebalance_db.txt + rm -rf $test_pool_data_path + + # setup + cp -rf $test_data_src $test_pool_data_path +} + +function assertions() { + # check error log is empty + if grep -q '[^[:space:]]' $log_error_file; then + echo "error log is not empty!" + cat $log_error_file + exit 1 + fi +} + +prepare +./zfs-inplace-rebalancing.sh $test_pool_data_path >> $log_std_file 2>> $log_error_file +cat $log_std_file +assertions + +prepare +./zfs-inplace-rebalancing.sh --checksum true --passes 1 $test_pool_data_path >> $log_std_file 2>> $log_error_file +cat $log_std_file +assertions + +prepare +./zfs-inplace-rebalancing.sh --checksum false $test_pool_data_path >> $log_std_file 2>> $log_error_file +cat $log_std_file +assertions diff --git a/zfs-inplace-rebalancing.sh b/zfs-inplace-rebalancing.sh index f29eb70..c957a1e 100755 --- a/zfs-inplace-rebalancing.sh +++ b/zfs-inplace-rebalancing.sh @@ -185,7 +185,7 @@ fi while true ; do case "$1" in -c | --checksum ) - if [ "$2" -eq 1 ] || [[ "$2" =~ (on|true|yes) ]]; then + if [[ "$2" == 1 || "$2" =~ (on|true|yes) ]]; then checksum_flag="true" else checksum_flag="false"