mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-04-19 05:40:13 +00:00
Format all /test files with black
Signed-off-by: Christian König <ckoenig@posteo.de>
This commit is contained in:
parent
0932c5c498
commit
0df38cd64e
7 changed files with 711 additions and 605 deletions
|
@ -1,22 +1,27 @@
|
|||
def test_key_val_replacement_works(host):
|
||||
''' Confirms addOrEditKeyValPair either adds or replaces a key value pair in a given file '''
|
||||
host.run('''
|
||||
"""Confirms addOrEditKeyValPair either adds or replaces a key value pair in a given file"""
|
||||
host.run(
|
||||
"""
|
||||
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"
|
||||
''')
|
||||
output = host.run('''
|
||||
"""
|
||||
)
|
||||
output = host.run(
|
||||
"""
|
||||
cat ./testoutput
|
||||
''')
|
||||
expected_stdout = 'KEY_ONE=value3\nKEY_TWO=value2\nKEY_FOUR=value4\n'
|
||||
"""
|
||||
)
|
||||
expected_stdout = "KEY_ONE=value3\nKEY_TWO=value2\nKEY_FOUR=value4\n"
|
||||
assert expected_stdout == output.stdout
|
||||
|
||||
|
||||
def test_key_addition_works(host):
|
||||
''' Confirms addKey adds a key (no value) to a file without duplicating it '''
|
||||
host.run('''
|
||||
"""Confirms addKey adds a key (no value) to a file without duplicating it"""
|
||||
host.run(
|
||||
"""
|
||||
source /opt/pihole/utils.sh
|
||||
addKey "./testoutput" "KEY_ONE"
|
||||
addKey "./testoutput" "KEY_ONE"
|
||||
|
@ -24,17 +29,21 @@ def test_key_addition_works(host):
|
|||
addKey "./testoutput" "KEY_TWO"
|
||||
addKey "./testoutput" "KEY_THREE"
|
||||
addKey "./testoutput" "KEY_THREE"
|
||||
''')
|
||||
output = host.run('''
|
||||
"""
|
||||
)
|
||||
output = host.run(
|
||||
"""
|
||||
cat ./testoutput
|
||||
''')
|
||||
expected_stdout = 'KEY_ONE\nKEY_TWO\nKEY_THREE\n'
|
||||
"""
|
||||
)
|
||||
expected_stdout = "KEY_ONE\nKEY_TWO\nKEY_THREE\n"
|
||||
assert expected_stdout == output.stdout
|
||||
|
||||
|
||||
def test_key_removal_works(host):
|
||||
''' Confirms removeKey removes a key or key/value pair '''
|
||||
host.run('''
|
||||
"""Confirms removeKey removes a key or key/value pair"""
|
||||
host.run(
|
||||
"""
|
||||
source /opt/pihole/utils.sh
|
||||
addOrEditKeyValPair "./testoutput" "KEY_ONE" "value1"
|
||||
addOrEditKeyValPair "./testoutput" "KEY_TWO" "value2"
|
||||
|
@ -42,81 +51,100 @@ def test_key_removal_works(host):
|
|||
addKey "./testoutput" "KEY_FOUR"
|
||||
removeKey "./testoutput" "KEY_TWO"
|
||||
removeKey "./testoutput" "KEY_FOUR"
|
||||
''')
|
||||
output = host.run('''
|
||||
"""
|
||||
)
|
||||
output = host.run(
|
||||
"""
|
||||
cat ./testoutput
|
||||
''')
|
||||
expected_stdout = 'KEY_ONE=value1\nKEY_THREE=value3\n'
|
||||
"""
|
||||
)
|
||||
expected_stdout = "KEY_ONE=value1\nKEY_THREE=value3\n"
|
||||
assert expected_stdout == output.stdout
|
||||
|
||||
|
||||
def test_getFTLAPIPortFile_default(host):
|
||||
''' Confirms getFTLAPIPortFile returns the default API port file path '''
|
||||
output = host.run('''
|
||||
"""Confirms getFTLAPIPortFile returns the default API port file path"""
|
||||
output = host.run(
|
||||
"""
|
||||
source /opt/pihole/utils.sh
|
||||
getFTLAPIPortFile
|
||||
''')
|
||||
expected_stdout = '/run/pihole-FTL.port\n'
|
||||
"""
|
||||
)
|
||||
expected_stdout = "/run/pihole-FTL.port\n"
|
||||
assert expected_stdout == output.stdout
|
||||
|
||||
|
||||
def test_getFTLAPIPort_default(host):
|
||||
''' Confirms getFTLAPIPort returns the default API port '''
|
||||
output = host.run('''
|
||||
"""Confirms getFTLAPIPort returns the default API port"""
|
||||
output = host.run(
|
||||
"""
|
||||
source /opt/pihole/utils.sh
|
||||
getFTLAPIPort "/run/pihole-FTL.port"
|
||||
''')
|
||||
expected_stdout = '4711\n'
|
||||
"""
|
||||
)
|
||||
expected_stdout = "4711\n"
|
||||
assert expected_stdout == output.stdout
|
||||
|
||||
|
||||
def test_getFTLAPIPortFile_and_getFTLAPIPort_custom(host):
|
||||
''' Confirms getFTLAPIPort returns a custom API port in a custom PORTFILE location '''
|
||||
host.run('''
|
||||
"""Confirms getFTLAPIPort returns a custom API port in a custom PORTFILE location"""
|
||||
host.run(
|
||||
"""
|
||||
tmpfile=$(mktemp)
|
||||
echo "PORTFILE=${tmpfile}" > /etc/pihole/pihole-FTL.conf
|
||||
echo "1234" > ${tmpfile}
|
||||
''')
|
||||
output = host.run('''
|
||||
"""
|
||||
)
|
||||
output = host.run(
|
||||
"""
|
||||
source /opt/pihole/utils.sh
|
||||
FTL_API_PORT_FILE=$(getFTLAPIPortFile)
|
||||
getFTLAPIPort "${FTL_API_PORT_FILE}"
|
||||
''')
|
||||
expected_stdout = '1234\n'
|
||||
"""
|
||||
)
|
||||
expected_stdout = "1234\n"
|
||||
assert expected_stdout == output.stdout
|
||||
|
||||
|
||||
def test_getFTLPIDFile_default(host):
|
||||
''' Confirms getFTLPIDFile returns the default PID file path '''
|
||||
output = host.run('''
|
||||
"""Confirms getFTLPIDFile returns the default PID file path"""
|
||||
output = host.run(
|
||||
"""
|
||||
source /opt/pihole/utils.sh
|
||||
getFTLPIDFile
|
||||
''')
|
||||
expected_stdout = '/run/pihole-FTL.pid\n'
|
||||
"""
|
||||
)
|
||||
expected_stdout = "/run/pihole-FTL.pid\n"
|
||||
assert expected_stdout == output.stdout
|
||||
|
||||
|
||||
def test_getFTLPID_default(host):
|
||||
''' Confirms getFTLPID returns the default value if FTL is not running '''
|
||||
output = host.run('''
|
||||
"""Confirms getFTLPID returns the default value if FTL is not running"""
|
||||
output = host.run(
|
||||
"""
|
||||
source /opt/pihole/utils.sh
|
||||
getFTLPID
|
||||
''')
|
||||
expected_stdout = '-1\n'
|
||||
"""
|
||||
)
|
||||
expected_stdout = "-1\n"
|
||||
assert expected_stdout == output.stdout
|
||||
|
||||
|
||||
def test_getFTLPIDFile_and_getFTLPID_custom(host):
|
||||
''' Confirms getFTLPIDFile returns a custom PID file path '''
|
||||
host.run('''
|
||||
"""Confirms getFTLPIDFile returns a custom PID file path"""
|
||||
host.run(
|
||||
"""
|
||||
tmpfile=$(mktemp)
|
||||
echo "PIDFILE=${tmpfile}" > /etc/pihole/pihole-FTL.conf
|
||||
echo "1234" > ${tmpfile}
|
||||
''')
|
||||
output = host.run('''
|
||||
"""
|
||||
)
|
||||
output = host.run(
|
||||
"""
|
||||
source /opt/pihole/utils.sh
|
||||
FTL_PID_FILE=$(getFTLPIDFile)
|
||||
getFTLPID "${FTL_PID_FILE}"
|
||||
''')
|
||||
expected_stdout = '1234\n'
|
||||
"""
|
||||
)
|
||||
expected_stdout = "1234\n"
|
||||
assert expected_stdout == output.stdout
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue