The Python-based test infrastructure (pytest, tox, testinfra) is replaced with BATS (Bash Automated Testing System), matching the approach already used in FTL Changes: - Add test/run.sh — single entry point replacing all 15 tox.*.ini files; accepts DISTRO env var, builds the test image, installs BATS on demand, and selects test files based on distro family (debian/alpine/rhel) - Add test/helpers/mocks.bash — bash equivalents of conftest.py's mock_command*, mock_command_2, and mock_command_passthrough helpers; uses base64 transfer to write mock scripts into containers safely - Add test/test_automated_install.bats — replaces test_any_automated_install.py - Add test/test_utils.bats — replaces test_any_utils.py - Add test/test_selinux.bats — replaces test_centos_fedora_common_support.py; only run on CentOS/Fedora (rhel family) - Remove conftest.py, requirements.txt, setup.py, __init__.py - Remove all 15 tox.*.ini files - Remove all three Python test files - Update .github/workflows/test.yml: drop Python setup, tox invocation, and black formatting check; distro-test job now runs bash test/run.sh - Update .gitignore: remove Python-specific entries, add test/libs/ Signed-off-by: PromoFaux <PromoFaux@users.noreply.github.com> Signed-off-by: Adam Warner <me@adamwarner.co.uk>
61 lines
1.7 KiB
Bash
Executable File
61 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bats
|
|
# Tests for utils.sh — translated from test_any_utils.py
|
|
|
|
load 'libs/bats-support/load'
|
|
load 'libs/bats-assert/load'
|
|
|
|
CID=""
|
|
|
|
setup() {
|
|
CID=$(docker run -d -t --cap-add=ALL "$IMAGE_TAG")
|
|
}
|
|
|
|
teardown() {
|
|
if [[ -n "$CID" ]]; then
|
|
docker rm -f "$CID" > /dev/null 2>&1 || true
|
|
fi
|
|
}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
@test "addOrEditKeyValPair adds and replaces key-value pairs correctly" {
|
|
docker exec "$CID" bash -c "
|
|
source /opt/pihole/utils.sh
|
|
addOrEditKeyValPair './testoutput' 'KEY_ONE' 'value1'
|
|
addOrEditKeyValPair './testoutput' 'KEY_TWO' 'value2'
|
|
addOrEditKeyValPair './testoutput' 'KEY_ONE' 'value3'
|
|
addOrEditKeyValPair './testoutput' 'KEY_FOUR' 'value4'
|
|
"
|
|
run docker exec "$CID" bash -c "cat ./testoutput"
|
|
assert_output "KEY_ONE=value3
|
|
KEY_TWO=value2
|
|
KEY_FOUR=value4"
|
|
}
|
|
|
|
@test "getFTLPID returns -1 when FTL is not running" {
|
|
run docker exec "$CID" bash -c "
|
|
source /opt/pihole/utils.sh
|
|
getFTLPID
|
|
"
|
|
assert_output "-1"
|
|
}
|
|
|
|
@test "setFTLConfigValue and getFTLConfigValue round-trip" {
|
|
# FTL must be installed for this test
|
|
docker exec "$CID" bash -c "
|
|
source /opt/pihole/basic-install.sh
|
|
create_pihole_user
|
|
funcOutput=\$(get_binary_name)
|
|
echo 'development' > /etc/pihole/ftlbranch
|
|
binary=\"pihole-FTL\${funcOutput##*pihole-FTL}\"
|
|
theRest=\"\${funcOutput%pihole-FTL*}\"
|
|
FTLdetect \"\${binary}\" \"\${theRest}\"
|
|
"
|
|
run docker exec "$CID" bash -c "
|
|
source /opt/pihole/utils.sh
|
|
setFTLConfigValue 'dns.upstreams' '[\"9.9.9.9\"]' > /dev/null
|
|
getFTLConfigValue 'dns.upstreams'
|
|
"
|
|
assert_output --partial "[ 9.9.9.9 ]"
|
|
}
|