mirror of
https://github.com/pi-hole/pi-hole.git
synced 2026-05-29 11:19:14 +02:00
e972c758ab
Split the BATS suite into two containers: one for mock/function tests and one for the fresh install, so installer tests can mutate the filesystem freely without teardown. Replace mocks.bash with bats-mock and bats-file, baked into the test images at build time via Docker ARG-versioned git clones. Improve the invalid-distro error to list available distros rather than printing an opaque Dockerfile path. Signed-off-by: Adam Warner <me@adamwarner.co.uk>
60 lines
1.8 KiB
Bash
Executable File
60 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bats
|
|
# Tests for utils.sh
|
|
|
|
load 'libs/bats-support/load'
|
|
load 'libs/bats-assert/load'
|
|
load 'libs/bats-file/load'
|
|
|
|
setup() {
|
|
TEST_TEMP_DIR="$(temp_make)"
|
|
}
|
|
|
|
teardown() {
|
|
temp_del "${TEST_TEMP_DIR}"
|
|
}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
@test "addOrEditKeyValPair adds and replaces key-value pairs correctly" {
|
|
local outfile="${TEST_TEMP_DIR}/testoutput"
|
|
bash -c "
|
|
source /opt/pihole/utils.sh
|
|
addOrEditKeyValPair '${outfile}' 'KEY_ONE' 'value1'
|
|
addOrEditKeyValPair '${outfile}' 'KEY_TWO' 'value2'
|
|
addOrEditKeyValPair '${outfile}' 'KEY_ONE' 'value3'
|
|
addOrEditKeyValPair '${outfile}' 'KEY_FOUR' 'value4'
|
|
"
|
|
assert_file_exists "${outfile}"
|
|
assert_file_contains "${outfile}" "KEY_ONE=value3"
|
|
assert_file_contains "${outfile}" "KEY_TWO=value2"
|
|
assert_file_contains "${outfile}" "KEY_FOUR=value4"
|
|
assert_file_not_contains "${outfile}" "KEY_ONE=value1"
|
|
}
|
|
|
|
@test "getFTLPID returns -1 when FTL is not running" {
|
|
run bash -c "
|
|
source /opt/pihole/utils.sh
|
|
getFTLPID
|
|
"
|
|
assert_output "-1"
|
|
}
|
|
|
|
@test "setFTLConfigValue and getFTLConfigValue round-trip" {
|
|
# FTL must be installed for this test
|
|
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 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 ]"
|
|
}
|