From 1cbb982d022ea849cdc2a9b043c496c6a6888bdd Mon Sep 17 00:00:00 2001 From: Jeremy Lecour Date: Sat, 25 Apr 2020 10:29:00 +0200 Subject: [PATCH] extract functions in test helpers --- test/test_helper.bash | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/test/test_helper.bash b/test/test_helper.bash index df8f644..92de516 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -9,11 +9,11 @@ setup() { set_variable "/etc/default/bkctld" "BACKUP_DISK" "/dev/vdb" - JAILNAME=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w15 | head -n1) + JAILNAME=$(random_jail_name) JAILPATH="/backup/jails/${JAILNAME}" INCSPATH="/backup/incs/${JAILNAME}" - PORT=$(awk -v min=2222 -v max=2999 'BEGIN{srand(); print int(min+rand()*(max-min+1))}') - INC_NAME=$(date +"%Y-%m-%d-%H") + PORT=$(random_port) + INC_NAME=$(inc_name_today) /usr/lib/bkctld/bkctld-init "${JAILNAME}" } @@ -23,6 +23,16 @@ teardown() { /usr/lib/bkctld/bkctld-remove "${JAILNAME}" && rm -rf "${INCSPATH}" } +random_jail_name() { + tr -cd '[:alnum:]' < /dev/urandom | fold -w15 | head -n1 +} +random_port() { + awk -v min=2222 -v max=2999 'BEGIN{srand(); print int(min+rand()*(max-min+1))}' +} +inc_name_today() { + date +"%Y-%m-%d-%H" +} + set_variable() { file=${1:?} var_name=${2:?}