mirror of
https://github.com/pi-hole/pi-hole
synced 2024-12-22 23:08:07 +00:00
Remove no-longer-needed utils
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
parent
76a6b42075
commit
764aa48c14
@ -25,7 +25,6 @@
|
||||
#
|
||||
# Example usage:
|
||||
# addOrEditKeyValPair "/etc/pihole/setupVars.conf" "BLOCKING_ENABLED" "true"
|
||||
# TODO: We miight not actually need this function in v6
|
||||
#######################
|
||||
addOrEditKeyValPair() {
|
||||
local file="${1}"
|
||||
@ -44,43 +43,6 @@ addOrEditKeyValPair() {
|
||||
fi
|
||||
}
|
||||
|
||||
#######################
|
||||
# Takes two arguments: file, and key.
|
||||
# Adds a key to target file
|
||||
#
|
||||
# Example usage:
|
||||
# addKey "/etc/dnsmasq.d/01-pihole.conf" "log-queries"
|
||||
#######################
|
||||
addKey(){
|
||||
local file="${1}"
|
||||
local key="${2}"
|
||||
|
||||
# touch file to prevent grep error if file does not exist yet
|
||||
touch "${file}"
|
||||
|
||||
# Match key against entire line, using both anchors. We assume
|
||||
# that the file's keys never have bounding whitespace. Anchors
|
||||
# are necessary to ensure the key is considered absent when it
|
||||
# is a substring of another key present in the file.
|
||||
if ! grep -q "^${key}$" "${file}"; then
|
||||
# Key does not exist, add it.
|
||||
echo "${key}" >> "${file}"
|
||||
fi
|
||||
}
|
||||
|
||||
#######################
|
||||
# Takes two arguments: file, and key.
|
||||
# Deletes a key or key/value pair from target file
|
||||
#
|
||||
# Example usage:
|
||||
# removeKey "/etc/pihole/setupVars.conf" "PIHOLE_DNS_1"
|
||||
#######################
|
||||
removeKey() {
|
||||
local file="${1}"
|
||||
local key="${2}"
|
||||
sed -i "/^${key}/d" "${file}"
|
||||
}
|
||||
|
||||
#######################
|
||||
# returns FTL's PID based on the content of the pihole-FTL.pid file
|
||||
#
|
||||
|
@ -18,70 +18,6 @@ def test_key_val_replacement_works(host):
|
||||
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(
|
||||
"""
|
||||
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_addition_substr(host):
|
||||
"""Confirms addKey adds substring keys (no value) to a file"""
|
||||
host.run(
|
||||
"""
|
||||
source /opt/pihole/utils.sh
|
||||
addKey "./testoutput" "KEY_ONE"
|
||||
addKey "./testoutput" "KEY_O"
|
||||
addKey "./testoutput" "KEY_TWO"
|
||||
addKey "./testoutput" "Y_TWO"
|
||||
"""
|
||||
)
|
||||
output = host.run(
|
||||
"""
|
||||
cat ./testoutput
|
||||
"""
|
||||
)
|
||||
expected_stdout = "KEY_ONE\nKEY_O\nKEY_TWO\nY_TWO\n"
|
||||
assert expected_stdout == output.stdout
|
||||
|
||||
|
||||
def test_key_removal_works(host):
|
||||
"""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"
|
||||
addOrEditKeyValPair "./testoutput" "KEY_THREE" "value3"
|
||||
addKey "./testoutput" "KEY_FOUR"
|
||||
removeKey "./testoutput" "KEY_TWO"
|
||||
removeKey "./testoutput" "KEY_FOUR"
|
||||
"""
|
||||
)
|
||||
output = host.run(
|
||||
"""
|
||||
cat ./testoutput
|
||||
"""
|
||||
)
|
||||
expected_stdout = "KEY_ONE=value1\nKEY_THREE=value3\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(
|
||||
|
Loading…
Reference in New Issue
Block a user