Skip to content

Commit

Permalink
add the unsupportedFunc monkeypatch (as mentioned by the readme addit…
Browse files Browse the repository at this point in the history
…ion) and add in tests for it

Signed-off-by: Adam Warner <[email protected]>
  • Loading branch information
PromoFaux committed Sep 27, 2023
1 parent 4c2d0ab commit b221a80
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,18 @@ RUN cd /etc/.pihole && \
install -T -m 0755 ./advanced/Templates/pihole-FTL-prestart.sh /opt/pihole/pihole-FTL-prestart.sh && \
install -T -m 0755 ./advanced/Templates/pihole-FTL-poststop.sh /opt/pihole/pihole-FTL-poststop.sh && \
addgroup -S pihole && adduser -S pihole -G pihole && \
echo "${PIHOLE_DOCKER_TAG}" > /pihole.docker.tag
echo "${PIHOLE_DOCKER_TAG}" > /pihole.docker.tag && \
# sed a new function into the `pihole` script just above the `helpFunc()` function for later use.
sed -i $'s/helpFunc() {/unsupportedFunc() {\\\n echo "Function not supported in Docker images"\\\n exit 0\\\n}\\\n\\\nhelpFunc() {/g' /usr/local/bin/pihole && \
# Replace a few of the `pihole` options with calls to `unsupportedFunc`:
# pihole -up / pihole updatePihole
sed -i $'s/)\s*updatePiholeFunc/) unsupportedFunc/g' /usr/local/bin/pihole && \
# pihole uninstall
sed -i $'s/)\s*uninstallFunc/) unsupportedFunc/g' /usr/local/bin/pihole && \
# pihole -r / pihole reconfigure
sed -i $'s/)\s*reconfigurePiholeFunc/) unsupportedFunc/g' /usr/local/bin/pihole && \
# pihole checkout
sed -i $'s/)\s*piholeCheckoutFunc/) unsupportedFunc/g' /usr/local/bin/pihole

COPY --chmod=0755 bash_functions.sh /usr/bin/bash_functions.sh
COPY --chmod=0755 start.sh /usr/bin/start.sh
Expand Down
14 changes: 14 additions & 0 deletions test/tests/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,17 @@ def test_pihole_ftl_clean_shutdown(docker):
)
assert "INFO: Shutting down... // exit code 0 // jmpret 0" in func.stdout
assert "INFO: ########## FTL terminated after" in func.stdout


# Ensure the unsupportedFunc monkeypatch is working
@pytest.mark.parametrize("test_args", ['-e "PH_VERBOSE=1"'])
def test_unsupported_monkeypatch(docker):
output = "Function not supported in Docker images"
checkout = docker.run("pihole checkout core dev")
update = docker.run("pihole -up")
uninstall = docker.run("pihole uninstall")
reconfigure = docker.run("pihole reconfigure")
assert output in checkout.stdout
assert output in update.stdout
assert output in uninstall.stdout
assert output in reconfigure.stdout

0 comments on commit b221a80

Please sign in to comment.