Skip to content

Commit

Permalink
Fix up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitry-ishenko authored and igorpecovnik committed Feb 4, 2025
1 parent 0ff69d3 commit 36735c0
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 29 deletions.
8 changes: 4 additions & 4 deletions tests/CON005.conf
Original file line number Diff line number Diff line change
@@ -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 $?
}
)}
5 changes: 3 additions & 2 deletions tests/DAT001.conf
Original file line number Diff line number Diff line change
@@ -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
}
)}
5 changes: 3 additions & 2 deletions tests/HAB001.conf
Original file line number Diff line number Diff line change
@@ -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
}
)}
6 changes: 4 additions & 2 deletions tests/HAS001.conf
Original file line number Diff line number Diff line change
@@ -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
)}
10 changes: 5 additions & 5 deletions tests/MAN001.conf
Original file line number Diff line number Diff line change
@@ -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 ]]
)}
9 changes: 5 additions & 4 deletions tests/MON001.conf
Original file line number Diff line number Diff line change
@@ -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
)}
9 changes: 4 additions & 5 deletions tests/NAV001.conf
Original file line number Diff line number Diff line change
@@ -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" ]]
)}
27 changes: 22 additions & 5 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
# 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
- RELEASE="bookworm:jammy:noble" run on specific or leave empty to run on all

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).

0 comments on commit 36735c0

Please sign in to comment.