From fef3aeadfac7eabe6b6dd3fee176a651f7f560f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 17 Sep 2018 18:51:51 +0200 Subject: [PATCH] Share test code between test suites --- tests/10_basic.tst | 13 +++---------- tests/20_allow_other.tst | 13 +++---------- tests/testhelpers.sh | 13 +++++++++++++ 3 files changed, 19 insertions(+), 20 deletions(-) create mode 100644 tests/testhelpers.sh diff --git a/tests/10_basic.tst b/tests/10_basic.tst index 32c56e4..e6241e3 100644 --- a/tests/10_basic.tst +++ b/tests/10_basic.tst @@ -1,16 +1,9 @@ #!/usr/bin/env testrunner.sh +source "$(dirname "$0")/testhelpers.sh" + function setup() { - test ! -z "$TEST_BUNDLE" - mount_dir=$(mktemp -d) - sparsebundlefs -s -f -D $TEST_BUNDLE $mount_dir & - pid=$! - for i in {0..50}; do - kill -0 $pid >/dev/null 2>&1 - # FIXME: Find actual mount callback in fuse? - grep -q "bundle has" $test_output_file && break || sleep 0.1 - done - dmg_file=$mount_dir/sparsebundle.dmg + mount_sparsebundle } function test_dmg_exists_after_mounting() { diff --git a/tests/20_allow_other.tst b/tests/20_allow_other.tst index b596266..9bf70d8 100644 --- a/tests/20_allow_other.tst +++ b/tests/20_allow_other.tst @@ -1,16 +1,9 @@ #!/usr/bin/env testrunner.sh +source "$(dirname "$0")/testhelpers.sh" + function setup() { - test ! -z "$TEST_BUNDLE" - mount_dir=$(mktemp -d) - sparsebundlefs -s -f -D -o allow_other $TEST_BUNDLE $mount_dir & - pid=$! - for i in {0..50}; do - kill -0 $pid >/dev/null 2>&1 - # FIXME: Find actual mount callback in fuse? - grep -q "bundle has" $test_output_file && break || sleep 0.1 - done - dmg_file=$mount_dir/sparsebundle.dmg + mount_sparsebundle -o allow_other } function test_dmg_has_correct_permissions() { diff --git a/tests/testhelpers.sh b/tests/testhelpers.sh new file mode 100644 index 0000000..cc1f91f --- /dev/null +++ b/tests/testhelpers.sh @@ -0,0 +1,13 @@ + +function mount_sparsebundle() { + test ! -z "$TEST_BUNDLE" + mount_dir=$(mktemp -d) + sparsebundlefs -s -f -D $* $TEST_BUNDLE $mount_dir & + pid=$! + for i in {0..50}; do + kill -0 $pid >/dev/null 2>&1 + # FIXME: Find actual mount callback in fuse? + grep -q "bundle has" $test_output_file && break || sleep 0.1 + done + dmg_file=$mount_dir/sparsebundle.dmg +}