Fix to debian lighttpd php config #19 w/tests

This commit is contained in:
diginc 2016-07-16 16:00:20 -05:00
parent 1ff52f72b3
commit b3879c8729
6 changed files with 84 additions and 3 deletions

3
.gitignore vendored
View File

@ -1,4 +1,7 @@
*.sw*
*.pyc
.cache
__pycache__
# WIP/test stuff
doco.yml

4
debian/start.sh vendored
View File

@ -1,6 +1,6 @@
#!/bin/sh
if [ -z "$ServerIP" ] ; then
echo "ERROR: It is required you pass an environment variables of 'ServerIP' with the IP of your docker host which you are passing 80/53 from"
echo "ERROR: To function correctly you must pass an environment variables of 'ServerIP' into the docker container with the IP of your docker host from which you are passing web (80) and dns (53) ports from"
exit 1
fi;
@ -12,7 +12,7 @@ sed -i "/bin-environment/ a\\\t\t\t\"PHP_ERROR_LOG\" => \"${PHP_ERROR_LOG}\"," $
if [ -n "$VIRTUAL_HOST" ] ; then
sed -i "/bin-environment/ a\\\t\t\t\"VIRTUAL_HOST\" => \"${VIRTUAL_HOST}\"," $PHP_ENV_CONFIG
else
echo "env[VIRTUAL_HOST] = ${ServerIP}" >> $PHP_ENV_CONFIG;
sed -i "/bin-environment/ a\\\t\t\t\"VIRTUAL_HOST\" => \"${ServerIP}\"," $PHP_ENV_CONFIG
fi;
echo "Added ENV to php:"

View File

@ -1,5 +1,5 @@
#!/bin/bash
image=${1:-'diginc/pihole:alpine'}
image=${1:-'diginc/pi-hole:alpine'}
IP=$(ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1)
# Default ports + daemonized docker container

View File

@ -1 +1,5 @@
docker-compose
pytest
pytest-xdist
pytest-cov
testinfra

60
test/conftest.py Normal file
View File

@ -0,0 +1,60 @@
import pytest
import testinfra
# Use testinfra to get a handy function to run commands locally
check_output = testinfra.get_backend(
"local://"
).get_module("Command").check_output
@pytest.fixture
def TestinfraBackend(request):
docker_run = "docker run -d {}".format(request.param)
print docker_run
docker_id = check_output(docker_run)
check_output("docker exec %s sed -i 's/^gravity_spinup/#donotcurl/g' /usr/local/bin/gravity.sh", docker_id)
def teardown():
check_output("docker rm -f %s", docker_id)
# Destroy the container at the end of the fixture life
request.addfinalizer(teardown)
# Return a dynamic created backend
return testinfra.get_backend("docker://" + docker_id)
def pytest_generate_tests(metafunc):
if "TestinfraBackend" in metafunc.fixturenames:
mark_args = getattr(metafunc.function, "docker_args", None)
docker_args = []
if mark_args is not None:
docker_args = docker_args + list(mark_args.args)
mark_images = getattr(metafunc.function, "docker_images", None)
images = ['diginc/pi-hole:alpine', 'diginc/pi-hole:debian']
if mark_images is not None:
images = mark_images.args
mark_cmd = getattr(metafunc.function, "docker_cmd", None)
command = 'tail -f /dev/null'
if mark_cmd is not None:
command = " ".join(mark_cmd.args)
docker_run_args = []
for img in images:
docker_run_args.append('{} {} {}'.format(" ".join(docker_args),
img, command))
# If the test has a destructive marker, we scope TestinfraBackend
# at function level (i.e. executing for each test). If not we scope
# at session level (i.e. all tests will share the same container)
if getattr(metafunc.function, "persistent", None) is not None:
scope = "session"
else:
scope = "function"
metafunc.parametrize(
"TestinfraBackend", docker_run_args, indirect=True, scope=scope)

14
test/test_start.py Normal file
View File

@ -0,0 +1,14 @@
import pytest
import testinfra
# This test will run on both debian:jessie and centos:7 images
def test_ServerIP_missing_env_triggers_error(Command):
start = Command.run('/start.sh')
error_msg = "ERROR: To function correctly you must pass an environment variables of 'ServerIP' into the docker container"
assert start.rc == 1
assert error_msg in start.stdout
@pytest.mark.docker_args('-e ServerIP="192.168.1.2"')
@pytest.mark.docker_cmd('/start.sh')
def test_ServerIP_allows_normal_startup(Command):
assert Command.run('pgrep -f /start.sh | wc') != 0