-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
run.sh
executable file
·51 lines (38 loc) · 1.29 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
set -eo pipefail
dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
image="$1"
# Build a client image with cgi-fcgi for testing
clientImage='librarytest/php-fpm-hello-web:fcgi'
docker build -t "$clientImage" - > /dev/null <<'EOF'
FROM debian:jessie
RUN set -x && apt-get update && apt-get install -y libfcgi0ldbl && rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["cgi-fcgi"]
EOF
# Create an instance of the container-under-test
cid="$(docker run -d -v "$dir/index.php":/var/www/html/index.php:ro "$image")"
trap "docker rm -f $cid > /dev/null" EXIT
# RACY TESTS ARE RACY
sleep 1
# TODO find a cleaner solution to this, similar to what we do in mysql-basics
fcgi-request() {
local method="$1"
local url="$2"
local queryString=
if [[ "$url" == *\?* ]]; then
queryString="${url#*\?}"
url="${url%%\?*}"
fi
docker run --rm -i --link "$cid":fpm \
-e REQUEST_METHOD="$method" \
-e SCRIPT_NAME="$url" \
-e SCRIPT_FILENAME=/var/www/html/"${url#/}" \
-e QUERY_STRING="$queryString" \
"$clientImage" \
-bind -connect fpm:9000
}
# Check that we can request /index.php with no params
[ -n "$(fcgi-request GET "/index.php")" ]
# Check that our index.php echoes the value of the "hello" param
hello="world-$RANDOM-$RANDOM"
[ "$(fcgi-request GET "/index.php?hello=$hello" | tail -1)" = "$hello" ]