Ignore commented lines when reding PRIVACYLEVEL from config file

Create dedicated getVal function in utils.sh as it might be useful somewhere else
Account for tailing comments and $key not being on the first line

Signed-off-by: Christian König <ckoenig@posteo.de>
This commit is contained in:
Christian König 2023-02-16 15:21:18 +01:00
parent 45cab12392
commit 4fd0f15d90
No known key found for this signature in database
3 changed files with 38 additions and 3 deletions

View file

@ -62,6 +62,22 @@ def test_key_removal_works(host):
assert expected_stdout == output.stdout
def test_get_value_works(host):
"""Confirms getVal returns the correct value for a given key"""
output = host.run(
"""
source /opt/pihole/utils.sh
echo "Somekey=xxx" >> /tmp/testfile
echo "#Testkey=1234" >> /tmp/testfile
echo "Testkey=5678" >> /tmp/testfile
echo "Testkey=abcd" >> /tmp/testfile
getVal "/tmp/testfile" "Testkey"
"""
)
expected_stdout = "5678"
assert expected_stdout == output.stdout
def test_getFTLAPIPort_default(host):
"""Confirms getFTLAPIPort returns the default API port"""
output = host.run(