Skip to content

Commit

Permalink
Merge pull request #46 from devilbox/unify-integration-tests
Browse files Browse the repository at this point in the history
Unify integration tests
  • Loading branch information
cytopia authored Mar 12, 2022
2 parents 7b563db + 329f048 commit a8f3984
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ test: update-readme

.PHONY: _test-integration
_test-integration:
./tests/test.sh $(IMAGE) $(ARCH)
./tests/start-ci.sh $(IMAGE) $(NAME) $(VERSION) $(DOCKER_TAG) $(ARCH)

.PHONY: update-readme
update-readme:
cat "./README.md" \
| perl -0 -pe "s/<!-- modules -->.*<!-- \/modules -->/<!-- modules -->\n$$(./tests/get-modules.sh $(IMAGE) $(ARCH))\n<!-- \/modules -->/s" \
| perl -0 -pe "s/<!-- modules -->.*<!-- \/modules -->/<!-- modules -->\n$$(./tests/get-modules.sh $(IMAGE) $(NAME) $(VERSION) $(DOCKER_TAG) $(ARCH))\n<!-- \/modules -->/s" \
> "./README.md.tmp"
yes | mv -f "./README.md.tmp" "./README.md"
git diff --quiet || { echo "Build Changes"; git diff; git status; false; }
20 changes: 20 additions & 0 deletions tests/01-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -eu
set -o pipefail

IMAGE="${1}"
#NAME="${2}"
VERSION="${3}"
TAG="${4}"
ARCH="${5}"


echo
echo "\$ docker run --rm --platform ${ARCH} --entrypoint=php ${IMAGE}:${TAG} -v | grep -E '^PHP ${VERSION}'"
docker run --rm --platform "${ARCH}" --entrypoint=php "${IMAGE}:${TAG}" -v | grep -E "^PHP ${VERSION}"
echo

echo
echo "\$ docker run --rm --platform ${ARCH} --entrypoint=php-fpm ${IMAGE}:${TAG} -v | grep -E '^PHP ${VERSION}'"
docker run --rm --platform "${ARCH}" --entrypoint=php-fpm "${IMAGE}:${TAG}" -v | grep -E "^PHP ${VERSION}"
echo
11 changes: 8 additions & 3 deletions tests/test.sh → tests/02-server-index.php.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
set -eu
set -o pipefail

CONT_PHP="${1}"
ARCH="${2}"
IMAGE="${1}"
#NAME="${2}"
#VERSION="${3}"
TAG="${4}"
ARCH="${5}"



###
### Variables
Expand Down Expand Up @@ -72,7 +77,7 @@ chmod 0644 "${DOC_ROOT_HOST}/error.php"
###
### Start containers
###
PHP_DID="$( docker run -d --platform "${ARCH}" --name "${NAME_PHP}" -v "${DOC_ROOT_HOST}:${DOC_ROOT_CONT}" "${CONT_PHP}" )"
PHP_DID="$( docker run -d --platform "${ARCH}" --name "${NAME_PHP}" -v "${DOC_ROOT_HOST}:${DOC_ROOT_CONT}" "${IMAGE}:${TAG}" )"
sleep 4
WEB_DID="$( docker run -d --platform "${ARCH}" --name "${NAME_WEB}" -v "${DOC_ROOT_HOST}:${DOC_ROOT_CONT}" -v "${CONFIG_HOST}:${CONFIG_CONT}" -p "${WWW_PORT}:80" --link "${NAME_PHP}" "${CONT_WEB}" )"
sleep 4
Expand Down
10 changes: 7 additions & 3 deletions tests/get-modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ set -e
set -u
set -o pipefail

IMAGE="${1:-devilbox/php-fpm-5.2}"
ARCH="${2:-linux/amd64}"

MODULES="$( docker run --rm -t --platform "${ARCH}" --entrypoint=php "${IMAGE}" -m \
IMAGE="${1}"
#NAME="${2}"
#VERSION="${3}"
TAG="${4}"
ARCH="${5}"

MODULES="$( docker run --rm -t --platform "${ARCH}" --entrypoint=php "${IMAGE}:${TAG}" -m \
| grep -vE '(^\[)|(^\s*$)' \
| sort -u -f
)"
Expand Down
48 changes: 48 additions & 0 deletions tests/start-ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash

set -e
set -u
set -o pipefail

###
### Variables
###

IFS=$'\n'

# Current directory
CWD="$( dirname "${0}" )"
IMAGE="${1}"
NAME="${2}"
VERSION="${3}"
TAG="${4}"
ARCH="${5}"

declare -a TESTS=()




###
### Run tests
###

# Get all [0-9]+.sh test files
FILES="$( find "${CWD}" -regex "${CWD}/[0-9].+\.sh" | sort -u )"
for f in ${FILES}; do
TESTS+=("${f}")
done

# Start a single test
if [ "${#}" -eq "3" ]; then
sh -c "${TESTS[${2}]} ${IMAGE} ${NAME} ${VERSION} ${TAG} ${ARCH}"

# Run all tests
else
for i in "${TESTS[@]}"; do
echo "################################################################################"
echo "# [${CWD}/${i}] ${IMAGE}:${TAG} ${NAME}-${VERSION} (${ARCH})"
echo "################################################################################"
sh -c "${i} ${IMAGE} ${NAME} ${VERSION} ${TAG} ${ARCH}"
done
fi

0 comments on commit a8f3984

Please sign in to comment.