Skip to content

Commit

Permalink
Merge pull request #21 from renatomefi/feature/tests-fixtures
Browse files Browse the repository at this point in the history
Create setup and tear down fixture for fpm changes
  • Loading branch information
renatomefi authored Feb 25, 2019
2 parents 553b070 + 87ac965 commit b3ba4e0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ test: ## Test code in multiple images
$(MAKE) test-image IMAGE="php:7.1-fpm-alpine3.8" DOCKERFILE="alpine"
$(MAKE) test-image IMAGE="php:7.2-fpm-alpine3.7" DOCKERFILE="alpine"
$(MAKE) test-image IMAGE="php:7.2-fpm-alpine3.8" DOCKERFILE="alpine"
$(MAKE) test-image IMAGE="php:7.3-rc-fpm-alpine3.8" DOCKERFILE="alpine"
$(MAKE) test-image IMAGE="php:7.3-fpm-alpine3.8" DOCKERFILE="alpine"
$(MAKE) test-image IMAGE="php:7.3-fpm-alpine3.9" DOCKERFILE="alpine"
$(MAKE) test-image IMAGE="php:7.1-fpm-stretch" DOCKERFILE="stretch"
$(MAKE) test-image IMAGE="php:7.2-fpm-stretch" DOCKERFILE="stretch"
$(MAKE) test-image IMAGE="php:7.3-rc-fpm-stretch" DOCKERFILE="stretch"
$(MAKE) test-image IMAGE="php:7.3-fpm-stretch" DOCKERFILE="stretch"

test-image:
./test/docker.sh ${DOCKERFILE} ${IMAGE}
Expand Down
36 changes: 21 additions & 15 deletions test/testinfra/test_fpm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import pytest

@pytest.fixture(scope="module")
def setup_fpm_fixture(host, request):
print('Backing up current fpm configuration')
host.run("cp /usr/local/etc/php-fpm.d/zz-docker.conf /tmp/zz-docker.conf")
yield 1
print('Recovering fpm configuration and reloading after module')
host.run("cp /tmp/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf")

@pytest.fixture
def setup_fpm_to_default_fixture(host, request, setup_fpm_fixture):
print('Recovering fpm configuration and reloading')
host.run("cp -f /tmp/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf")
host.run("kill -USR2 1")

@pytest.mark.php_fpm
def test_exit_when_no_status_page_is_configured(host):
def test_exit_when_no_status_page_is_configured(host, setup_fpm_to_default_fixture):
# disable fpm status page
host.run("sed -i /usr/local/etc/php-fpm.d/zz-docker.conf -e '/pm.status_path/ s/^;*/;/'")
host.run("kill -USR2 1")
Expand All @@ -12,12 +26,8 @@ def test_exit_when_no_status_page_is_configured(host):
assert "status output:" in cmd.stdout
assert "php-fpm status page non reachable" in cmd.stderr

# enable fpm status page back
host.run("sed -i /usr/local/etc/php-fpm.d/zz-docker.conf -e '/;pm.status_path/ s/^;*//'")
host.run("kill -USR2 1")

@pytest.mark.php_fpm
def test_fpm_on_socket(host):
def test_fpm_on_socket(host, setup_fpm_to_default_fixture):
# change fpm to socket
host.run("sed -i /usr/local/etc/php-fpm.d/zz-docker.conf -e '/^listen/ s/.*/listen = \\/var\\/run\\/php-fpm.sock/'")
host.run("kill -USR2 1")
Expand All @@ -28,39 +38,35 @@ def test_fpm_on_socket(host):
assert "status output:" in cmd.stdout
assert "pool:" in cmd.stdout

# change fpm back to port 9000
host.run("sed -i /usr/local/etc/php-fpm.d/zz-docker.conf -e '/^listen/ s/.*/listen = 9000/'")
host.run("kill -USR2 1")

# https://github.com/renatomefi/php-fpm-healthcheck/issues/18
@pytest.mark.php_fpm
def test_fpm_on_socket_with_huge_env(host):
def test_fpm_on_socket_with_huge_env(host, setup_fpm_to_default_fixture):
cmd = host.run("HUGE_ENV=\"$(dd if=/dev/zero bs=8192 count=1 | tr '\\000' '\\040')\" php-fpm-healthcheck -v")
assert cmd.rc == 0
assert "Trying to connect to php-fpm via:" in cmd.stdout
assert "status output:" in cmd.stdout
assert "pool:" in cmd.stdout

@pytest.mark.alpine
def test_exit_when_fpm_is_not_reachable_apk(host):
def test_exit_when_fpm_is_not_reachable_apk(host, setup_fpm_to_default_fixture):
cmd = host.run("FCGI_CONNECT=localhost:9001 php-fpm-healthcheck -v")
assert cmd.rc == 9
assert "Trying to connect to php-fpm via: localhost:9001" in cmd.stdout

@pytest.mark.alpine
def test_exit_when_fpm_is_invalid_host_apk(host):
def test_exit_when_fpm_is_invalid_host_apk(host, setup_fpm_to_default_fixture):
cmd = host.run("FCGI_CONNECT=abc php-fpm-healthcheck -v")
assert cmd.rc == 9
assert "Trying to connect to php-fpm via: abc" in cmd.stdout

@pytest.mark.stretch
def test_exit_when_fpm_is_not_reachable_apt(host):
def test_exit_when_fpm_is_not_reachable_apt(host, setup_fpm_to_default_fixture):
cmd = host.run("FCGI_CONNECT=localhost:9001 php-fpm-healthcheck -v")
assert cmd.rc == 111
assert "Trying to connect to php-fpm via: localhost:9001" in cmd.stdout

@pytest.mark.stretch
def test_exit_when_fpm_is_invalid_host_apt(host):
def test_exit_when_fpm_is_invalid_host_apt(host, setup_fpm_to_default_fixture):
cmd = host.run("FCGI_CONNECT=abc php-fpm-healthcheck -v")
assert cmd.rc == 2
assert "Trying to connect to php-fpm via: abc" in cmd.stdout

0 comments on commit b3ba4e0

Please sign in to comment.