Skip to content

Improve tests #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: feature/d8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ jobs:
- name: Test images
run: |
./tests/image_verify.sh --source tests/expectations --env-file tests/envfile --http-port 80 --user root $IMAGE_NAME:$TAG_1_13
./tests/image_verify.sh --source tests/overrides/expectations --env-file tests/overrides/envfile --http-port 4321 --user root $IMAGE_NAME:$TAG_1_13
./tests/image_verify.sh --source tests/overrides/expectations --env-file tests/overrides/envfile --http-port 4321 --http-host nginx_default_server_name --user root $IMAGE_NAME:$TAG_1_13
./tests/image_verify.sh --source tests/expectations --env-file tests/envfile --http-port 80 --user root $IMAGE_NAME:$TAG_1_17
./tests/image_verify.sh --source tests/overrides/expectations --env-file tests/overrides/envfile --http-port 4321 --user root $IMAGE_NAME:$TAG_1_17
./tests/image_verify.sh --source tests/overrides/expectations --env-file tests/overrides/envfile --http-port 4321 --http-host nginx_default_server_name --user root $IMAGE_NAME:$TAG_1_17
./tests/image_verify.sh --source tests/expectations --env-file tests/envfile --http-port 8080 --user "unknown uid 1001" $IMAGE_NAME:$TAG_1_13_RL
./tests/image_verify.sh --source tests/overrides/expectations --env-file tests/overrides/envfile --http-port 4321 --user "unknown uid 1001" $IMAGE_NAME:$TAG_1_13_RL
./tests/image_verify.sh --source tests/overrides/expectations --env-file tests/overrides/envfile --http-port 4321 --http-host nginx_default_server_name --user "unknown uid 1001" $IMAGE_NAME:$TAG_1_13_RL
./tests/image_verify.sh --source tests/expectations --env-file tests/envfile --http-port 8080 --user "unknown uid 1001" $IMAGE_NAME:$TAG_1_17_RL
./tests/image_verify.sh --source tests/overrides/expectations --env-file tests/overrides/envfile --http-port 4321 --user "unknown uid 1001" $IMAGE_NAME:$TAG_1_17_RL
./tests/image_verify.sh --source tests/overrides/expectations --env-file tests/overrides/envfile --http-port 4321 --http-host nginx_default_server_name --user "unknown uid 1001" $IMAGE_NAME:$TAG_1_17_RL

deploy:
needs: test
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ build:

test:
./tests/image_verify.sh --source tests/expectations --env-file tests/envfile --http-port 80 --user root sparkfabrik/docker-php-drupal-nginx:1.13.6-alpine.d8
./tests/image_verify.sh --source tests/overrides/expectations --env-file tests/overrides/envfile --http-port 4321 --user root sparkfabrik/docker-php-drupal-nginx:1.13.6-alpine.d8
./tests/image_verify.sh --source tests/overrides/expectations --env-file tests/overrides/envfile --http-port 4321 --http-host nginx_default_server_name --user root sparkfabrik/docker-php-drupal-nginx:1.13.6-alpine.d8
./tests/image_verify.sh --source tests/expectations --env-file tests/envfile --http-port 80 --user root sparkfabrik/docker-php-drupal-nginx:1.17.6-alpine.d8
./tests/image_verify.sh --source tests/overrides/expectations --env-file tests/overrides/envfile --http-port 4321 --user root sparkfabrik/docker-php-drupal-nginx:1.17.6-alpine.d8
./tests/image_verify.sh --source tests/overrides/expectations --env-file tests/overrides/envfile --http-port 4321 --http-host nginx_default_server_name --user root sparkfabrik/docker-php-drupal-nginx:1.17.6-alpine.d8

build-rootless:
docker build -f Dockerfile-1.13.6-alpine -t sparkfabrik/docker-php-drupal-nginx:1.13.6-alpine.d8-rootless --build-arg user=1001 .
docker build -f Dockerfile-1.17.6-alpine -t sparkfabrik/docker-php-drupal-nginx:1.17.6-alpine.d8-rootless --build-arg user=1001 .

test-rootless:
./tests/image_verify.sh --source tests/expectations --env-file tests/envfile --http-port 8080 --user "unknown uid 1001" sparkfabrik/docker-php-drupal-nginx:1.13.6-alpine.d8-rootless
./tests/image_verify.sh --source tests/overrides/expectations --env-file tests/overrides/envfile --http-port 4321 --user "unknown uid 1001" sparkfabrik/docker-php-drupal-nginx:1.13.6-alpine.d8-rootless
./tests/image_verify.sh --source tests/overrides/expectations --env-file tests/overrides/envfile --http-port 4321 --http-host nginx_default_server_name --user "unknown uid 1001" sparkfabrik/docker-php-drupal-nginx:1.13.6-alpine.d8-rootless
./tests/image_verify.sh --source tests/expectations --env-file tests/envfile --http-port 8080 --user "unknown uid 1001" sparkfabrik/docker-php-drupal-nginx:1.17.6-alpine.d8-rootless
./tests/image_verify.sh --source tests/overrides/expectations --env-file tests/overrides/envfile --http-port 4321 --user "unknown uid 1001" sparkfabrik/docker-php-drupal-nginx:1.17.6-alpine.d8-rootless
./tests/image_verify.sh --source tests/overrides/expectations --env-file tests/overrides/envfile --http-port 4321 --http-host nginx_default_server_name --user "unknown uid 1001" sparkfabrik/docker-php-drupal-nginx:1.17.6-alpine.d8-rootless
29 changes: 23 additions & 6 deletions tests/image_verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ DOCKER_TEST_IMAGE="alpine/httpie:latest"
DOCKER_TEST_IP=""
DOCKER_TEST_PORT=80
DOCKER_TEST_PROTO="http"
DOCKER_TEST_HOST=""

DOCKER_TEST_OUTPUT=""
DOCKER_TEST_HEADER_REQ=""
Expand Down Expand Up @@ -51,6 +52,7 @@ printf "%-${PAD}s %s\n" "DOCKER_TEST_IMAGE" "${DOCKER_TEST_IMAGE}"
printf "%-${PAD}s %s\n" "DOCKER_IMAGE" "${DOCKER_IMAGE}"
printf "%-${PAD}s %s\n" "PORT" "${DOCKER_TEST_PORT}"
printf "%-${PAD}s %s\n" "PROTO" "${DOCKER_TEST_PROTO}"
printf "%-${PAD}s %s\n" "HOST" "${DOCKER_TEST_HOST}"
printf "%-${PAD}s %s\n" "ENV_LIST" "${ENV_LIST}"
printf "%-${PAD}s %s\n" "ENV_FILE" "${ENV_FILE}"
printf "%-${PAD}s %s\n" "SOURCE_FILE" "${SOURCE_FILE}"
Expand Down Expand Up @@ -99,6 +101,7 @@ Options:
the container image (these variables will override the --env defined ones)
--http-port N Defines the HTTP port, if missing the default 80 port is used
--http-proto STRING [http|https] Defines the HTTP protocol to use, if missing the default http is used
--http-host STRING Defines the HTTP HOST to use, if missing the empty header is used
--source PATH Defines a path for a file which includes the desired expectations
--user,-u STRING Defines the default user for the image
EOM
Expand Down Expand Up @@ -128,6 +131,7 @@ while [ -n "${1}" ]; do
--env-file) ENV_FILE="${2}"; if [ ! -f "${ENV_FILE}" ]; then exit 3; fi; shift 2 ;;
--http-port) DOCKER_TEST_PORT="${2}"; shift 2 ;;
--http-proto) DOCKER_TEST_PROTO="${2}"; shift 2 ;;
--http-host) DOCKER_TEST_HOST="${2}"; shift 2 ;;
--source) SOURCE_FILE="${2}"; if [ ! -f "${SOURCE_FILE}" ]; then exit 2; fi; shift 2 ;;
--user|-u) TEST_USER="${2}"; shift 2 ;;
-*|--*=) echo "Error: Unsupported flag $1" >&2; exit 1 ;;
Expand Down Expand Up @@ -277,6 +281,15 @@ fi
# exit 8
# fi

stop_container() {
if [ -n "${CONTAINER_ID}" ]; then
if [ $DEBUG -eq 1 ]; then
echo "Docker stop command: docker stop ${CONTAINER_ID} >/dev/null 2>&1"
fi
docker stop ${CONTAINER_ID} >/dev/null 2>&1
fi
}

echo "Start testing process on image: ${DOCKER_IMAGE} ..."

EXIT_STATUS=0
Expand All @@ -288,6 +301,7 @@ fi
CONTAINER_ID=$(docker run ${DOCKER_ENV} --rm -d -v ${PWD}/tests/html:/var/www/html ${DOCKER_IMAGE})
if [ $? -ne 0 ]; then
echo "Failed to start the docker image"
stop_container
exit 9
fi

Expand All @@ -301,15 +315,21 @@ fi
DOCKER_TEST_IP=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${CONTAINER_ID})
if [ $? -ne 0 ]; then
echo "Failed to discover the IP address of the docker image"
stop_container
exit 10
fi

HTTP_HEADERS=""
if [ -n "${DOCKER_TEST_HOST}" ]; then
HTTP_HEADERS="${HTTP_HEADERS} Host:${DOCKER_TEST_HOST}"
fi
if [ $DEBUG -eq 1 ]; then
echo "Get the data: docker run --rm ${DOCKER_TEST_IMAGE} -p HhBb GET ${DOCKER_TEST_PROTO}://${DOCKER_TEST_IP}:${DOCKER_TEST_PORT}/test.html"
echo "Get the data: docker run --rm ${DOCKER_TEST_IMAGE} -p HhBb GET ${DOCKER_TEST_PROTO}://${DOCKER_TEST_IP}:${DOCKER_TEST_PORT}/test.html ${HTTP_HEADERS}"
fi
DOCKER_TEST_OUTPUT=$(docker run --rm ${DOCKER_TEST_IMAGE} -p HhBb GET ${DOCKER_TEST_PROTO}://${DOCKER_TEST_IP}:${DOCKER_TEST_PORT}/test.html)
DOCKER_TEST_OUTPUT=$(docker run --rm ${DOCKER_TEST_IMAGE} -p HhBb GET ${DOCKER_TEST_PROTO}://${DOCKER_TEST_IP}:${DOCKER_TEST_PORT}/test.html ${HTTP_HEADERS})
if [ $? -ne 0 ]; then
echo "Failed to get the data"
stop_container
exit 11
fi

Expand Down Expand Up @@ -378,10 +398,7 @@ if [ -n "${TEST_USER}" ]; then
test_for_user
fi

if [ $DEBUG -eq 1 ]; then
echo "Docker stop command: docker stop ${CONTAINER_ID} >/dev/null 2>&1"
fi
docker stop ${CONTAINER_ID} >/dev/null 2>&1
stop_container

if [ $EXIT_STATUS -eq 0 ]; then
echo "\e[32mSUCCESS, all tests passed\e[39m"
Expand Down
3 changes: 2 additions & 1 deletion tests/overrides/envfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PHP_HOST=localhost
NGINX_DEFAULT_SERVER_NAME=nginx_default_server_name
NGINX_DEFAULT_SERVER_PORT=4321
NGINX_DEFAULT_ROOT=/var/www/html/folder
NGINX_DEFAULT_ROOT=/var/www/html/folder
1 change: 1 addition & 0 deletions tests/overrides/expectations
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
HTTP_STATUS="200 OK"
HEADER_REQ_Host=nginx_default_server_name
BODY_RES=<h1>It works in another folder</h1>
HEADER_RES_Server=nginx
HEADER_RES_Content-Type=text/html