2022-01-30 23:05:28 +00:00
|
|
|
def test_key_val_replacement_works(host):
|
2022-04-19 17:35:00 +00:00
|
|
|
''' Confirms addOrEditKeyValPair either adds or replaces a key value pair in a given file '''
|
2022-01-30 23:05:28 +00:00
|
|
|
host.run('''
|
|
|
|
source /opt/pihole/utils.sh
|
2022-03-16 20:46:15 +00:00
|
|
|
addOrEditKeyValPair "./testoutput" "KEY_ONE" "value1"
|
|
|
|
addOrEditKeyValPair "./testoutput" "KEY_TWO" "value2"
|
|
|
|
addOrEditKeyValPair "./testoutput" "KEY_ONE" "value3"
|
|
|
|
addOrEditKeyValPair "./testoutput" "KEY_FOUR" "value4"
|
2022-01-30 23:05:28 +00:00
|
|
|
''')
|
|
|
|
output = host.run('''
|
|
|
|
cat ./testoutput
|
|
|
|
''')
|
2022-04-19 17:35:00 +00:00
|
|
|
expected_stdout = 'KEY_ONE=value3\nKEY_TWO=value2\nKEY_FOUR=value4\n'
|
2022-03-16 17:42:01 +00:00
|
|
|
assert expected_stdout == output.stdout
|
|
|
|
|
2022-03-16 20:46:15 +00:00
|
|
|
|
2022-04-19 17:35:00 +00:00
|
|
|
def test_key_addition_works(host):
|
|
|
|
''' 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"
|
|
|
|
addKey "./testoutput" "KEY_TWO"
|
|
|
|
addKey "./testoutput" "KEY_TWO"
|
|
|
|
addKey "./testoutput" "KEY_THREE"
|
|
|
|
addKey "./testoutput" "KEY_THREE"
|
|
|
|
''')
|
|
|
|
output = host.run('''
|
|
|
|
cat ./testoutput
|
|
|
|
''')
|
|
|
|
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 '''
|
2022-03-16 17:42:01 +00:00
|
|
|
host.run('''
|
|
|
|
source /opt/pihole/utils.sh
|
2022-03-16 20:46:15 +00:00
|
|
|
addOrEditKeyValPair "./testoutput" "KEY_ONE" "value1"
|
|
|
|
addOrEditKeyValPair "./testoutput" "KEY_TWO" "value2"
|
|
|
|
addOrEditKeyValPair "./testoutput" "KEY_THREE" "value3"
|
2022-04-19 17:35:00 +00:00
|
|
|
addKey "./testoutput" "KEY_FOUR"
|
2022-04-04 21:02:26 +00:00
|
|
|
removeKey "./testoutput" "KEY_TWO"
|
2022-04-19 17:35:00 +00:00
|
|
|
removeKey "./testoutput" "KEY_FOUR"
|
2022-03-16 17:42:01 +00:00
|
|
|
''')
|
|
|
|
output = host.run('''
|
|
|
|
cat ./testoutput
|
|
|
|
''')
|
|
|
|
expected_stdout = 'KEY_ONE=value1\nKEY_THREE=value3\n'
|
2022-01-30 23:05:28 +00:00
|
|
|
assert expected_stdout == output.stdout
|
2022-02-20 21:24:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_getFTLAPIPort_default(host):
|
|
|
|
''' Confirms getFTLAPIPort returns the default API port '''
|
|
|
|
output = host.run('''
|
|
|
|
source /opt/pihole/utils.sh
|
|
|
|
getFTLAPIPort
|
|
|
|
''')
|
|
|
|
expected_stdout = '4711\n'
|
|
|
|
assert expected_stdout == output.stdout
|
|
|
|
|
|
|
|
|
|
|
|
def test_getFTLAPIPort_custom(host):
|
|
|
|
''' Confirms getFTLAPIPort returns a custom API port in a custom PORTFILE location '''
|
|
|
|
host.run('''
|
|
|
|
echo "PORTFILE=/tmp/port.file" > /etc/pihole/pihole-FTL.conf
|
|
|
|
echo "1234" > /tmp/port.file
|
|
|
|
''')
|
|
|
|
output = host.run('''
|
|
|
|
source /opt/pihole/utils.sh
|
|
|
|
getFTLAPIPort
|
|
|
|
''')
|
|
|
|
expected_stdout = '1234\n'
|
|
|
|
assert expected_stdout == output.stdout
|