feat(init): first commit
This commit is contained in:
114
tests/lib.sh
Normal file
114
tests/lib.sh
Normal file
@ -0,0 +1,114 @@
|
||||
#!/bin/bash
|
||||
|
||||
log() { printf '%s\n' "$*"; }
|
||||
error() { log "ERROR: $*" >&2; }
|
||||
fatal() { error "$@"; exit 1; }
|
||||
|
||||
run_symfony_app_container() {
|
||||
set -e
|
||||
trap "set +e" RETURN
|
||||
|
||||
local symfony_version=${1}
|
||||
local php_version=${2}
|
||||
local image_tag=${3}
|
||||
|
||||
cd "${SCRIPT_DIR}/.."
|
||||
|
||||
# Create temporary directory
|
||||
local project_dir=$(mktemp -d)
|
||||
local run_id=$(date +%s)
|
||||
|
||||
# Defer cleanup on exit
|
||||
trap_add "rm -rf ${project_dir}" EXIT
|
||||
|
||||
# Create dummy Symfony project
|
||||
symfony new --dir="${project_dir}" --version="${symfony_version}" --php="${php_version}" --webapp 1>&2
|
||||
|
||||
cat > "${project_dir}/Dockerfile" <<EOF
|
||||
FROM reg.cadoles.com/cadoles/symfony:${image_tag}
|
||||
EOF
|
||||
|
||||
cat > "${project_dir}/.dockerignore" <<EOF
|
||||
/var
|
||||
/vendor
|
||||
EOF
|
||||
|
||||
local image_name="symfony-test-${image_tag}:${run_id}"
|
||||
|
||||
# Build Symfony project image
|
||||
docker build \
|
||||
-t "${image_name}" \
|
||||
"${project_dir}" \
|
||||
1>&2
|
||||
|
||||
local http_port=$(get_unused_port)
|
||||
local container_name="symfony-test-${image_tag}-${run_id}"
|
||||
|
||||
# Start project image
|
||||
docker run \
|
||||
-d \
|
||||
--rm \
|
||||
-p "${http_port}:8080" \
|
||||
--name "${container_name}" \
|
||||
"${image_name}" \
|
||||
1>&2
|
||||
|
||||
# Wait container is healthy with a timeout
|
||||
local duration=0
|
||||
local last_tick=$(date +%s)
|
||||
local container_status=$(docker inspect -f '{{.State.Health.Status}}' ${container_name})
|
||||
|
||||
log "Waiting for container to become healthy..." 1>&2
|
||||
until [ "${container_status}" == "healthy" ]; do
|
||||
sleep 1
|
||||
|
||||
local now=$(date +%s)
|
||||
duration=$(( ${duration} + ( ${now} - ${last_tick} ) ))
|
||||
|
||||
|
||||
if [ ${duration} -gt 60 ]; then
|
||||
fail "Container did not become healthy before timeout !"
|
||||
fi
|
||||
|
||||
last_tick=${now}
|
||||
container_status=$(docker inspect -f '{{.State.Health.Status}}' ${container_name})
|
||||
done
|
||||
|
||||
echo "${container_name}"
|
||||
}
|
||||
|
||||
get_unused_port() {
|
||||
set -e
|
||||
trap "set +e" RETURN
|
||||
|
||||
local lport=32768;
|
||||
local uport=60999;
|
||||
while true; do
|
||||
local mport=$[${lport} + (${RANDOM} % $uport)];
|
||||
(echo "" >/dev/tcp/127.0.0.1/${mport}) >/dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
echo ${mport};
|
||||
return 0;
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# From https://stackoverflow.com/a/7287873
|
||||
trap_add() {
|
||||
local trap_add_cmd=$1;
|
||||
shift || fatal "${FUNCNAME} usage error"
|
||||
for trap_add_name in "$@"; do
|
||||
trap -- "$(
|
||||
# helper fn to get existing trap command from output
|
||||
# of trap -p
|
||||
extract_trap_cmd() { printf '%s\n' "$3"; }
|
||||
# print existing trap command with newline
|
||||
eval "extract_trap_cmd $(trap -p "${trap_add_name}")"
|
||||
# print the new trap command
|
||||
printf '%s\n' "${trap_add_cmd}"
|
||||
)" "${trap_add_name}" \
|
||||
|| fatal "unable to add to trap ${trap_add_name}"
|
||||
done
|
||||
}
|
||||
|
||||
declare -f -t trap_add
|
23
tests/test_alpine-sp-oidc.sh
Normal file
23
tests/test_alpine-sp-oidc.sh
Normal file
@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )";
|
||||
|
||||
source "$SCRIPT_DIR/lib.sh"
|
||||
|
||||
# Test reg.cadoles.com/cadoles/symfony:alpine-php-7.4-standalone with Symfony 4.4
|
||||
test_alpine_sp_oidc() {
|
||||
# FIXME
|
||||
|
||||
local container_name=$(run_symfony_app_container "4.4" "7.4" "alpine-php-7.4-standalone")
|
||||
local image_name=$(docker inspect -f '{{.Config.Image}}' ${container_name})
|
||||
|
||||
trap_add "docker kill ${container_name}" EXIT
|
||||
trap_add "docker rmi -f ${image_name}" EXIT
|
||||
|
||||
local app_url="http://$(docker port ${container_name} 8080/tcp)"
|
||||
|
||||
# Check that application is responding as expected
|
||||
local page_content=$(curl -s "${app_url}" | pandoc -f html -t plain)
|
||||
|
||||
assert_matches 'Welcome to Symfony 4\.4\.*' "${page_content}" "Could not find Symfony default welcome message !"
|
||||
}
|
Reference in New Issue
Block a user