Skip to content

Commit

Permalink
Test against Debian Stretch and Dash
Browse files Browse the repository at this point in the history
Fixes #2
By testing Debian Stretch we validate also how it's working on dash,
since busybox tends to implement bash features.
The solution was to split Dockerfiles and mark the tests which can't be
run in both distros.
  • Loading branch information
renatomefi committed Sep 18, 2018
1 parent 5fea01b commit 8e13418
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 19 deletions.
16 changes: 10 additions & 6 deletions .circleci/config.yml
Expand Up @@ -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"
20 changes: 12 additions & 8 deletions Makefile
Expand Up @@ -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}
2 changes: 1 addition & 1 deletion test/Dockerfile → 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
Expand Down
11 changes: 11 additions & 0 deletions 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/
9 changes: 6 additions & 3 deletions test/docker.sh
Expand Up @@ -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")
Expand All @@ -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"
2 changes: 2 additions & 0 deletions 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")

Expand Down
17 changes: 16 additions & 1 deletion test/testinfra/test_execution.py
@@ -1,23 +1,27 @@
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

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
Expand All @@ -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")
1 change: 1 addition & 0 deletions 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
Expand Down
2 changes: 2 additions & 0 deletions 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
Expand Down

0 comments on commit 8e13418

Please sign in to comment.