diff --git a/tests/CON005.conf b/tests/CON005.conf index 31331da5..0ebb906c 100644 --- a/tests/CON005.conf +++ b/tests/CON005.conf @@ -1,8 +1,8 @@ ENABLED=true RELEASE="bookworm:noble" -function testcase { - ./bin/armbian-config --api module_portainer remove +testcase() {( + set -e + ./bin/armbian-config --api module_portainer install ./bin/armbian-config --api module_portainer status - echo $? -} +)} diff --git a/tests/DAT001.conf b/tests/DAT001.conf index 478655ea..58f13f49 100644 --- a/tests/DAT001.conf +++ b/tests/DAT001.conf @@ -1,7 +1,8 @@ ENABLED=false -function testcase { +testcase() {( + set -e ./bin/armbian-config --api module_mariadb install ./bin/armbian-config --api module_mariadb status docker container ls -a -} +)} diff --git a/tests/HAB001.conf b/tests/HAB001.conf index 3825313c..7be41674 100644 --- a/tests/HAB001.conf +++ b/tests/HAB001.conf @@ -1,7 +1,8 @@ ENABLED=true RELEASE="bookworm" -function testcase { +function testcase {( + set -e ./bin/armbian-config --api module_openhab install systemctl is-active --quiet openhab.service -} +)} diff --git a/tests/HAS001.conf b/tests/HAS001.conf index ca200ad9..8469dec2 100644 --- a/tests/HAS001.conf +++ b/tests/HAS001.conf @@ -1,6 +1,8 @@ ENABLED=false RELEASE="bookworm" -function testcase { +testcase() {( + set -e ./bin/armbian-config --api module_haos install -} + ./bin/armbian-config --api module_haos status +)} diff --git a/tests/MAN001.conf b/tests/MAN001.conf index a7bbbe90..578cfd0a 100644 --- a/tests/MAN001.conf +++ b/tests/MAN001.conf @@ -1,9 +1,9 @@ ENABLED=true RELEASE="bookworm:noble" # run on specific or leave empty to run on all -function testcase { - ./bin/armbian-config --api module_cockpit remove +testcase() {( + set -e + ./bin/armbian-config --api module_cockpit remove || true ./bin/armbian-config --api module_cockpit install - [ -f /usr/bin/cockpit-bridge ] -} - + [[ -f /usr/bin/cockpit-bridge ]] +)} diff --git a/tests/MON001.conf b/tests/MON001.conf index 92b1f676..ff7959ca 100644 --- a/tests/MON001.conf +++ b/tests/MON001.conf @@ -1,10 +1,11 @@ ENABLED=true RELEASE="bookworm:noble" -function testcase { - ./bin/armbian-config --api module_uptimekuma remove +testcase() {( + set -e + ./bin/armbian-config --api module_uptimekuma remove || true ./bin/armbian-config --api module_uptimekuma install ./bin/armbian-config --api module_uptimekuma status ./bin/armbian-config --api module_uptimekuma remove - ./bin/armbian-config --api module_uptimekuma status -} + ! ./bin/armbian-config --api module_uptimekuma status +)} diff --git a/tests/NAV001.conf b/tests/NAV001.conf index 22180852..a3d9d4d1 100644 --- a/tests/NAV001.conf +++ b/tests/NAV001.conf @@ -1,11 +1,10 @@ ENABLED=true RELEASE="bookworm:noble" -function testcase { +testcase() {( + set -e ./bin/armbian-config --api module_navidrome remove ./bin/armbian-config --api module_navidrome install container=$(docker container ls -a | mawk '/navidrome?( |$)/{print $1}') - if [[ -z "${container}" ]]; then - exit 1 - fi -} + [[ -n "$container" ]] +)} diff --git a/tests/README.md b/tests/README.md index d35c1065..dacc30bd 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,6 +1,6 @@ # Unit tests -If function testcase returns 0, test is succesful. Put the code there. +If the function `testcase()` returns 0, the test is succesful. Put the code there. - name of the the file is function ID.conf - ENABLED=false|true @@ -8,12 +8,29 @@ If function testcase returns 0, test is succesful. Put the code there. Example: -``` +```sh ENABLED=true RELEASE="bookworm:noble" -function testcase { - ./bin/armbian-config --api module_cockpit install - [ -f /usr/bin/cockpit-bridge ] +testcase() { + ./bin/armbian-config --api module_cockpit install + [ -f /usr/bin/cockpit-bridge ] } ``` + +If you have multiple test conditions inside `testcase()` and you want the test +to exit on the first failed statement, you can use the following technique: + +```sh +testcase() {( + set -e + ./bin/armbian-config --api pkg_install neovim + ./bin/armbian-config --api pkg_installed neovim + ./bin/armbian-config --api pkg_remove neovim + ! ./bin/armbian-config --api pkg_installed neovim +)} +``` + +Note the additional pair of `()` and the `set -e` command inside function body. +These will cause test conditions to run inside a subshell with the -e option +enabled (exit immediately if a pipeline returns non-zero status).