mirror of
https://github.com/pi-hole/pi-hole
synced 2024-12-22 14:58:08 +00:00
no longer need to write bash test scripts
This commit is contained in:
parent
a5a067d50f
commit
d2f815bba7
@ -20,15 +20,15 @@ def test_setupVars_are_sourced_to_global_scope(Pihole):
|
|||||||
Pihole.run(setup_var_file)
|
Pihole.run(setup_var_file)
|
||||||
|
|
||||||
script = dedent('''\
|
script = dedent('''\
|
||||||
#!/bin/bash -e
|
set -e
|
||||||
printSetupVars() {
|
printSetupVars() {
|
||||||
# Currently debug test function only
|
# Currently debug test function only
|
||||||
echo "Outputting sourced variables"
|
echo "Outputting sourced variables"
|
||||||
echo "PIHOLE_INTERFACE=\${PIHOLE_INTERFACE}"
|
echo "PIHOLE_INTERFACE=${PIHOLE_INTERFACE}"
|
||||||
echo "IPV4_ADDRESS=\${IPV4_ADDRESS}"
|
echo "IPV4_ADDRESS=${IPV4_ADDRESS}"
|
||||||
echo "IPV6_ADDRESS=\${IPV6_ADDRESS}"
|
echo "IPV6_ADDRESS=${IPV6_ADDRESS}"
|
||||||
echo "PIHOLE_DNS_1=\${PIHOLE_DNS_1}"
|
echo "PIHOLE_DNS_1=${PIHOLE_DNS_1}"
|
||||||
echo "PIHOLE_DNS_2=\${PIHOLE_DNS_2}"
|
echo "PIHOLE_DNS_2=${PIHOLE_DNS_2}"
|
||||||
}
|
}
|
||||||
update_dialogs() {
|
update_dialogs() {
|
||||||
. /etc/pihole/setupVars.conf
|
. /etc/pihole/setupVars.conf
|
||||||
@ -50,7 +50,7 @@ def test_setupVars_saved_to_file(Pihole):
|
|||||||
Pihole.run(set_setup_vars).stdout
|
Pihole.run(set_setup_vars).stdout
|
||||||
|
|
||||||
script = dedent('''\
|
script = dedent('''\
|
||||||
#!/bin/bash -e
|
set -e
|
||||||
echo start
|
echo start
|
||||||
TERM=xterm
|
TERM=xterm
|
||||||
PHTEST=TRUE
|
PHTEST=TRUE
|
||||||
@ -100,17 +100,7 @@ def mock_command(script, result, container):
|
|||||||
print container.run('cat {}'.format(full_script_path)).stdout
|
print container.run('cat {}'.format(full_script_path)).stdout
|
||||||
|
|
||||||
|
|
||||||
def run_script(Pihole, script, file="/test.sh"):
|
def run_script(Pihole, script):
|
||||||
_write_test_script(Pihole, script, file=file)
|
result = Pihole.run(script)
|
||||||
result = Pihole.run(file)
|
|
||||||
assert result.rc == 0
|
assert result.rc == 0
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _write_test_script(Pihole, script, file):
|
|
||||||
''' Running the test script blocks directly can behave differently with regard to global vars '''
|
|
||||||
''' this is a cheap work around to that until all functions no longer rely on global variables '''
|
|
||||||
''' found out why, dash: is the default in testinfra run() for Docker
|
|
||||||
Should try and convert the tests using this to firewalld style test
|
|
||||||
or override the run() function to use bash instead '''
|
|
||||||
Pihole.run('cat <<EOF> {file}\n{script}\nEOF'.format(file=file, script=script))
|
|
||||||
Pihole.run('chmod +x {}'.format(file))
|
|
||||||
|
Loading…
Reference in New Issue
Block a user