Skip to content

Commit 8e13418

Browse files
committed
Test against Debian Stretch and Dash
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.
1 parent 5fea01b commit 8e13418

File tree

9 files changed

+61
-19
lines changed

9 files changed

+61
-19
lines changed

.circleci/config.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,28 @@ jobs:
3030
machine: true
3131
steps:
3232
- checkout
33-
- run: make test-image IMAGE="php:fpm-alpine"
33+
- run: make test-image IMAGE="php:fpm-alpine" DOCKERFILE="alpine"
34+
- run: make test-image IMAGE="php:fpm-stretch" DOCKERFILE="stretch"
3435

3536
test-7.1:
3637
machine: true
3738
steps:
3839
- checkout
39-
- run: make test-image IMAGE="php:7.1-fpm-alpine3.7"
40-
- run: make test-image IMAGE="php:7.1-fpm-alpine3.8"
40+
- run: make test-image IMAGE="php:7.1-fpm-alpine3.7" DOCKERFILE="alpine"
41+
- run: make test-image IMAGE="php:7.1-fpm-alpine3.8" DOCKERFILE="alpine"
42+
- run: make test-image IMAGE="php:7.1-fpm-stretch" DOCKERFILE="stretch"
4143

4244
test-7.2:
4345
machine: true
4446
steps:
4547
- checkout
46-
- run: make test-image IMAGE="php:7.2-fpm-alpine3.7"
47-
- run: make test-image IMAGE="php:7.2-fpm-alpine3.8"
48+
- run: make test-image IMAGE="php:7.2-fpm-alpine3.7" DOCKERFILE="alpine"
49+
- run: make test-image IMAGE="php:7.2-fpm-alpine3.8" DOCKERFILE="alpine"
50+
- run: make test-image IMAGE="php:7.2-fpm-stretch" DOCKERFILE="stretch"
4851

4952
test-7.3:
5053
machine: true
5154
steps:
5255
- checkout
53-
- run: make test-image IMAGE="php:7.3-rc-fpm-alpine3.8"
56+
- run: make test-image IMAGE="php:7.3-rc-fpm-alpine3.8" DOCKERFILE="alpine"
57+
- run: make test-image IMAGE="php:7.3-rc-fpm-stretch" DOCKERFILE="stretch"

Makefile

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ current_dir := $(abspath $(patsubst %/,%,$(dir $(mkfile_path))))
66
.PHONY: *
77

88
lint: php-fpm-healthcheck
9-
docker run --rm -v ${current_dir}:/mnt:ro koalaman/shellcheck ./php-fpm-healthcheck ./test/*.sh
9+
docker run --rm -v ${current_dir}:/mnt:ro koalaman/shellcheck \
10+
./php-fpm-healthcheck ./test/*.sh
1011

1112
test:
12-
$(MAKE) test-image IMAGE="php:fpm-alpine"
13-
$(MAKE) test-image IMAGE="php:7.1-fpm-alpine3.7"
14-
$(MAKE) test-image IMAGE="php:7.1-fpm-alpine3.8"
15-
$(MAKE) test-image IMAGE="php:7.2-fpm-alpine3.7"
16-
$(MAKE) test-image IMAGE="php:7.2-fpm-alpine3.8"
17-
$(MAKE) test-image IMAGE="php:7.3-rc-fpm-alpine3.8"
13+
$(MAKE) test-image IMAGE="php:fpm-alpine" DOCKERFILE="alpine"
14+
$(MAKE) test-image IMAGE="php:7.1-fpm-alpine3.7" DOCKERFILE="alpine"
15+
$(MAKE) test-image IMAGE="php:7.1-fpm-alpine3.8" DOCKERFILE="alpine"
16+
$(MAKE) test-image IMAGE="php:7.2-fpm-alpine3.7" DOCKERFILE="alpine"
17+
$(MAKE) test-image IMAGE="php:7.2-fpm-alpine3.8" DOCKERFILE="alpine"
18+
$(MAKE) test-image IMAGE="php:7.3-rc-fpm-alpine3.8" DOCKERFILE="alpine"
19+
$(MAKE) test-image IMAGE="php:7.1-fpm-stretch" DOCKERFILE="stretch"
20+
$(MAKE) test-image IMAGE="php:7.2-fpm-stretch" DOCKERFILE="stretch"
21+
$(MAKE) test-image IMAGE="php:7.3-rc-fpm-stretch" DOCKERFILE="stretch"
1822

1923
test-image:
20-
./test/docker.sh ${IMAGE}
24+
./test/docker.sh ${DOCKERFILE} ${IMAGE}

test/Dockerfile renamed to test/Dockerfile-alpine

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM php:7.2-fpm-alpine3.8
22

33
# Required software
4-
RUN apk add --no-cache fcgi
4+
RUN apk add --no-cache fcgi
55

66
# Enable php fpm status page
77
RUN set -xe && echo "pm.status_path = /status" >> /usr/local/etc/php-fpm.d/zz-docker.conf

test/Dockerfile-stretch

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM php:7.2-fpm-stretch
2+
3+
# Required software
4+
RUN set -x \
5+
&& apt-get update \
6+
&& apt-get install -y libfcgi-bin
7+
8+
# Enable php fpm status page
9+
RUN set -xe && echo "pm.status_path = /status" >> /usr/local/etc/php-fpm.d/zz-docker.conf
10+
11+
COPY ./php-fpm-healthcheck /usr/local/bin/

test/docker.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ docker stop "$CONTAINER" 1> /dev/null
1414
}
1515
trap cleanup EXIT
1616

17-
declare -r DOCKER_IMAGE="$1"
17+
declare -r DOCKER_FILE="$1"
18+
declare -r DOCKER_IMAGE="$2"
1819

1920
declare DOCKER_TAG_TEMPORARY
2021
DOCKER_TAG_TEMPORARY="$DOCKER_IMAGE-$(date +%s)"
2122

22-
sed "s/FROM .*/FROM $DOCKER_IMAGE/g" ./test/Dockerfile | docker build -t "$DOCKER_TAG_TEMPORARY" -f - .
23+
sed "s/FROM .*/FROM $DOCKER_IMAGE/g" "./test/Dockerfile-$DOCKER_FILE" | docker build -t "$DOCKER_TAG_TEMPORARY" -f - .
2324

2425
declare CONTAINER
2526
CONTAINER=$(docker run -d --rm "$DOCKER_TAG_TEMPORARY")
@@ -30,4 +31,6 @@ TESTS_DIR="$(pwd)/test"
3031
docker run --rm -t \
3132
-v "$TESTS_DIR:/tests" \
3233
-v /var/run/docker.sock:/var/run/docker.sock:ro \
33-
renatomefi/docker-testinfra:latest --verbose --hosts="docker://$CONTAINER"
34+
renatomefi/docker-testinfra:latest \
35+
--verbose --hosts="docker://$CONTAINER" \
36+
-m "php_fpm or $DOCKER_FILE"

test/testinfra/test_command.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import pytest
22

3+
@pytest.mark.php_fpm
34
def test_healthcheck_script_is_available(host):
45
cmd = host.run("which php-fpm-healthcheck")
56
assert cmd.rc == 0
67

8+
@pytest.mark.php_fpm
79
def test_healthcheck_script_is_executable(host):
810
scriptFile = host.check_output("which php-fpm-healthcheck")
911

test/testinfra/test_execution.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
import pytest
22

3+
@pytest.mark.php_fpm
34
def test_invalid_option_exits_properly(host):
45
cmd = host.run("php-fpm-healthcheck --invalid-option")
56
assert cmd.rc == 3
67

78
cmd = host.run("php-fpm-healthcheck --invalid-option=")
89
assert cmd.rc == 3
910

11+
@pytest.mark.php_fpm
1012
def test_valid_with_empty_value_exits_properly(host):
1113
cmd = host.run("php-fpm-healthcheck --listen-queue-len=")
1214
assert cmd.rc == 3
1315
assert "option value must be an integer" in cmd.stderr
1416

17+
@pytest.mark.php_fpm
1518
def test_valid_with_non_integer_value_exits_properly(host):
1619
cmd = host.run("php-fpm-healthcheck --listen-queue-len=abc")
1720
assert cmd.rc == 3
1821
assert "option value must be an integer" in cmd.stderr
1922

20-
def test_missing_fcgi(host):
23+
@pytest.mark.alpine
24+
def test_missing_fcgi_apk(host):
2125
host.run("apk del fcgi")
2226
cmd = host.run("php-fpm-healthcheck")
2327
assert cmd.rc == 4
@@ -26,3 +30,14 @@ def test_missing_fcgi(host):
2630
# Fail safe for other tests, maybe we could use a docker fixture
2731
# to start a new container everytime
2832
host.run("apk add --no-cache fcgi")
33+
34+
@pytest.mark.stretch
35+
def test_missing_fcgi_apt(host):
36+
host.run("apt-get remove -y libfcgi-bin")
37+
cmd = host.run("php-fpm-healthcheck")
38+
assert cmd.rc == 4
39+
assert "Make sure fcgi is installed" in cmd.stderr
40+
41+
# Fail safe for other tests, maybe we could use a docker fixture
42+
# to start a new container everytime
43+
host.run("apt-get install -y libfcgi-bin")

test/testinfra/test_metrics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22

3+
@pytest.mark.php_fpm
34
def test_metric_accepted_conn(host):
45
cmd = host.run("php-fpm-healthcheck -v")
56
assert cmd.rc == 0

test/testinfra/test_ping.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import pytest
22

3+
@pytest.mark.php_fpm
34
def test_ping(host):
45
cmd = host.run("php-fpm-healthcheck")
56
assert cmd.rc == 0
67

8+
@pytest.mark.php_fpm
79
def test_ping_verbose(host):
810
cmd = host.run("php-fpm-healthcheck -v")
911
assert cmd.rc == 0

0 commit comments

Comments
 (0)