diff --git a/.circleci/config.yml b/.circleci/config.yml index 830228d..40a5015 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -30,24 +30,28 @@ jobs: machine: true steps: - checkout - - run: make test-image IMAGE="php:fpm-alpine" + - run: make test-image IMAGE="php:fpm-alpine" DOCKERFILE="alpine" + - run: make test-image IMAGE="php:fpm-stretch" DOCKERFILE="stretch" test-7.1: machine: true steps: - checkout - - run: make test-image IMAGE="php:7.1-fpm-alpine3.7" - - run: make test-image IMAGE="php:7.1-fpm-alpine3.8" + - run: make test-image IMAGE="php:7.1-fpm-alpine3.7" DOCKERFILE="alpine" + - run: make test-image IMAGE="php:7.1-fpm-alpine3.8" DOCKERFILE="alpine" + - run: make test-image IMAGE="php:7.1-fpm-stretch" DOCKERFILE="stretch" test-7.2: machine: true steps: - checkout - - run: make test-image IMAGE="php:7.2-fpm-alpine3.7" - - run: make test-image IMAGE="php:7.2-fpm-alpine3.8" + - run: make test-image IMAGE="php:7.2-fpm-alpine3.7" DOCKERFILE="alpine" + - run: make test-image IMAGE="php:7.2-fpm-alpine3.8" DOCKERFILE="alpine" + - run: make test-image IMAGE="php:7.2-fpm-stretch" DOCKERFILE="stretch" test-7.3: machine: true steps: - checkout - - run: make test-image IMAGE="php:7.3-rc-fpm-alpine3.8" + - run: make test-image IMAGE="php:7.3-rc-fpm-alpine3.8" DOCKERFILE="alpine" + - run: make test-image IMAGE="php:7.3-rc-fpm-stretch" DOCKERFILE="stretch" diff --git a/Makefile b/Makefile index 711d38c..c23f53f 100644 --- a/Makefile +++ b/Makefile @@ -6,15 +6,19 @@ current_dir := $(abspath $(patsubst %/,%,$(dir $(mkfile_path)))) .PHONY: * lint: php-fpm-healthcheck - docker run --rm -v ${current_dir}:/mnt:ro koalaman/shellcheck ./php-fpm-healthcheck ./test/*.sh + docker run --rm -v ${current_dir}:/mnt:ro koalaman/shellcheck \ + ./php-fpm-healthcheck ./test/*.sh test: - $(MAKE) test-image IMAGE="php:fpm-alpine" - $(MAKE) test-image IMAGE="php:7.1-fpm-alpine3.7" - $(MAKE) test-image IMAGE="php:7.1-fpm-alpine3.8" - $(MAKE) test-image IMAGE="php:7.2-fpm-alpine3.7" - $(MAKE) test-image IMAGE="php:7.2-fpm-alpine3.8" - $(MAKE) test-image IMAGE="php:7.3-rc-fpm-alpine3.8" + $(MAKE) test-image IMAGE="php:fpm-alpine" DOCKERFILE="alpine" + $(MAKE) test-image IMAGE="php:7.1-fpm-alpine3.7" DOCKERFILE="alpine" + $(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.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" test-image: - ./test/docker.sh ${IMAGE} + ./test/docker.sh ${DOCKERFILE} ${IMAGE} diff --git a/test/Dockerfile b/test/Dockerfile-alpine similarity index 87% rename from test/Dockerfile rename to test/Dockerfile-alpine index adef1e0..598de0a 100644 --- a/test/Dockerfile +++ b/test/Dockerfile-alpine @@ -1,7 +1,7 @@ FROM php:7.2-fpm-alpine3.8 # Required software -RUN apk add --no-cache fcgi +RUN apk add --no-cache fcgi # Enable php fpm status page RUN set -xe && echo "pm.status_path = /status" >> /usr/local/etc/php-fpm.d/zz-docker.conf diff --git a/test/Dockerfile-stretch b/test/Dockerfile-stretch new file mode 100644 index 0000000..adcb3d3 --- /dev/null +++ b/test/Dockerfile-stretch @@ -0,0 +1,11 @@ +FROM php:7.2-fpm-stretch + +# Required software +RUN set -x \ + && apt-get update \ + && apt-get install -y libfcgi-bin + +# Enable php fpm status page +RUN set -xe && echo "pm.status_path = /status" >> /usr/local/etc/php-fpm.d/zz-docker.conf + +COPY ./php-fpm-healthcheck /usr/local/bin/ diff --git a/test/docker.sh b/test/docker.sh index e9360f9..e75fd14 100755 --- a/test/docker.sh +++ b/test/docker.sh @@ -14,12 +14,13 @@ docker stop "$CONTAINER" 1> /dev/null } trap cleanup EXIT -declare -r DOCKER_IMAGE="$1" +declare -r DOCKER_FILE="$1" +declare -r DOCKER_IMAGE="$2" declare DOCKER_TAG_TEMPORARY DOCKER_TAG_TEMPORARY="$DOCKER_IMAGE-$(date +%s)" -sed "s/FROM .*/FROM $DOCKER_IMAGE/g" ./test/Dockerfile | docker build -t "$DOCKER_TAG_TEMPORARY" -f - . +sed "s/FROM .*/FROM $DOCKER_IMAGE/g" "./test/Dockerfile-$DOCKER_FILE" | docker build -t "$DOCKER_TAG_TEMPORARY" -f - . declare CONTAINER CONTAINER=$(docker run -d --rm "$DOCKER_TAG_TEMPORARY") @@ -30,4 +31,6 @@ TESTS_DIR="$(pwd)/test" docker run --rm -t \ -v "$TESTS_DIR:/tests" \ -v /var/run/docker.sock:/var/run/docker.sock:ro \ - renatomefi/docker-testinfra:latest --verbose --hosts="docker://$CONTAINER" + renatomefi/docker-testinfra:latest \ + --verbose --hosts="docker://$CONTAINER" \ + -m "php_fpm or $DOCKER_FILE" diff --git a/test/testinfra/test_command.py b/test/testinfra/test_command.py index 1c8b493..16964fa 100644 --- a/test/testinfra/test_command.py +++ b/test/testinfra/test_command.py @@ -1,9 +1,11 @@ import pytest +@pytest.mark.php_fpm def test_healthcheck_script_is_available(host): cmd = host.run("which php-fpm-healthcheck") assert cmd.rc == 0 +@pytest.mark.php_fpm def test_healthcheck_script_is_executable(host): scriptFile = host.check_output("which php-fpm-healthcheck") diff --git a/test/testinfra/test_execution.py b/test/testinfra/test_execution.py index 1f0e396..ac0cedb 100644 --- a/test/testinfra/test_execution.py +++ b/test/testinfra/test_execution.py @@ -1,5 +1,6 @@ import pytest +@pytest.mark.php_fpm def test_invalid_option_exits_properly(host): cmd = host.run("php-fpm-healthcheck --invalid-option") assert cmd.rc == 3 @@ -7,17 +8,20 @@ def test_invalid_option_exits_properly(host): cmd = host.run("php-fpm-healthcheck --invalid-option=") assert cmd.rc == 3 +@pytest.mark.php_fpm def test_valid_with_empty_value_exits_properly(host): cmd = host.run("php-fpm-healthcheck --listen-queue-len=") assert cmd.rc == 3 assert "option value must be an integer" in cmd.stderr +@pytest.mark.php_fpm def test_valid_with_non_integer_value_exits_properly(host): cmd = host.run("php-fpm-healthcheck --listen-queue-len=abc") assert cmd.rc == 3 assert "option value must be an integer" in cmd.stderr -def test_missing_fcgi(host): +@pytest.mark.alpine +def test_missing_fcgi_apk(host): host.run("apk del fcgi") cmd = host.run("php-fpm-healthcheck") assert cmd.rc == 4 @@ -26,3 +30,14 @@ def test_missing_fcgi(host): # Fail safe for other tests, maybe we could use a docker fixture # to start a new container everytime host.run("apk add --no-cache fcgi") + +@pytest.mark.stretch +def test_missing_fcgi_apt(host): + host.run("apt-get remove -y libfcgi-bin") + cmd = host.run("php-fpm-healthcheck") + assert cmd.rc == 4 + assert "Make sure fcgi is installed" in cmd.stderr + + # Fail safe for other tests, maybe we could use a docker fixture + # to start a new container everytime + host.run("apt-get install -y libfcgi-bin") diff --git a/test/testinfra/test_metrics.py b/test/testinfra/test_metrics.py index 80d2b84..86983d9 100644 --- a/test/testinfra/test_metrics.py +++ b/test/testinfra/test_metrics.py @@ -1,5 +1,6 @@ import pytest +@pytest.mark.php_fpm def test_metric_accepted_conn(host): cmd = host.run("php-fpm-healthcheck -v") assert cmd.rc == 0 diff --git a/test/testinfra/test_ping.py b/test/testinfra/test_ping.py index e52ff28..5493d96 100644 --- a/test/testinfra/test_ping.py +++ b/test/testinfra/test_ping.py @@ -1,9 +1,11 @@ import pytest +@pytest.mark.php_fpm def test_ping(host): cmd = host.run("php-fpm-healthcheck") assert cmd.rc == 0 +@pytest.mark.php_fpm def test_ping_verbose(host): cmd = host.run("php-fpm-healthcheck -v") assert cmd.rc == 0