diff --git a/advanced/Scripts/utils.sh b/advanced/Scripts/utils.sh index 67301394..63d51f87 100755 --- a/advanced/Scripts/utils.sh +++ b/advanced/Scripts/utils.sh @@ -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 # diff --git a/test/test_any_utils.py b/test/test_any_utils.py index 59745c48..cf6cc7e6 100644 --- a/test/test_any_utils.py +++ b/test/test_any_utils.py @@ -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(