Attempt at modifying firewall rules for testing.
This commit is contained in:
parent
f7a17248b7
commit
1317b67657
|
@ -65,8 +65,8 @@ def test_setupVars_saved_to_file(Pihole):
|
||||||
assert "{}={}".format(k, v) in output
|
assert "{}={}".format(k, v) in output
|
||||||
|
|
||||||
def test_configureFirewall_firewalld_no_errors(Pihole):
|
def test_configureFirewall_firewalld_no_errors(Pihole):
|
||||||
''' confirms firewalld rules are applied when appopriate '''
|
''' confirms firewalld rules are applied when appropriate '''
|
||||||
mock_command('firewall-cmd', '0', Pihole)
|
mock_command('firewall-cmd', 'running', '0', Pihole)
|
||||||
configureFirewall = Pihole.run('''
|
configureFirewall = Pihole.run('''
|
||||||
source /opt/pihole/basic-install.sh
|
source /opt/pihole/basic-install.sh
|
||||||
configureFirewall
|
configureFirewall
|
||||||
|
@ -80,19 +80,21 @@ def test_configureFirewall_firewalld_no_errors(Pihole):
|
||||||
|
|
||||||
|
|
||||||
# Helper functions
|
# Helper functions
|
||||||
def mock_command(script, result, container):
|
def mock_command(script, result, retVal, container):
|
||||||
''' Allows for setup of commands we don't really want to have to run for real in unit tests '''
|
''' Allows for setup of commands we don't really want to have to run for real in unit tests '''
|
||||||
''' TODO: support array of results that enable the results to change over multiple executions of a command '''
|
''' TODO: support array of results that enable the results to change over multiple executions of a command '''
|
||||||
|
container.run('''
|
||||||
|
cat <<EOF> {script}\n{content}\nEOF
|
||||||
|
echo {result}
|
||||||
|
chmod +x {script}
|
||||||
|
'''.format(script=full_script_path, content=mock_script, result=result))
|
||||||
full_script_path = '/usr/local/bin/{}'.format(script)
|
full_script_path = '/usr/local/bin/{}'.format(script)
|
||||||
mock_script = dedent('''\
|
mock_script = dedent('''\
|
||||||
#!/bin/bash -e
|
#!/bin/bash -e
|
||||||
echo "\$0 \$@" >> /var/log/{script}
|
echo "\$0 \$@" >> /var/log/{script}
|
||||||
|
|
||||||
exit {retcode}
|
exit {retcode}
|
||||||
'''.format(script=script, retcode=result))
|
'''.format(script=script, retcode=retVal))
|
||||||
container.run('''
|
|
||||||
cat <<EOF> {script}\n{content}\nEOF
|
|
||||||
chmod +x {script}
|
|
||||||
'''.format(script=full_script_path, content=mock_script))
|
|
||||||
|
|
||||||
def run_script(Pihole, script):
|
def run_script(Pihole, script):
|
||||||
result = Pihole.run(script)
|
result = Pihole.run(script)
|
||||||
|
|
Loading…
Reference in New Issue