Skip to content

Commit b768802

Browse files
committed
Tests: added templates-stream
1 parent a96463b commit b768802

4 files changed

Lines changed: 60 additions & 0 deletions

File tree

.test/config.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ imageTests+=(
55
templates-http
66
templates-resolver
77
templates-resolver-ipv6
8+
templates-stream
89
workers
910
modules
1011
'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
example.com - OK
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
3+
[ "$DEBUG" ] && set -x
4+
5+
set -eo pipefail
6+
7+
dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
8+
9+
image="$1"
10+
11+
clientImage='alpine:latest'
12+
# ensure the clientImage is ready and available
13+
if ! docker image inspect "$clientImage" &> /dev/null; then
14+
docker pull "$clientImage" > /dev/null
15+
fi
16+
17+
# Create an instance of the container-under-test
18+
serverImage="$("$HOME/oi/test/tests/image-name.sh" librarytest/nginx-template "$image")"
19+
"$HOME/oi/test/tests/docker-build.sh" "$dir" "$serverImage" <<EOD
20+
FROM $image
21+
22+
RUN rm -f /etc/nginx/conf.d/default.conf
23+
24+
COPY dir/server.conf.template /etc/nginx/templates/server.conf.stream-template
25+
EOD
26+
cid="$(docker run -d -e NGINX_MY_SERVER_NAME=example.com "$serverImage")"
27+
trap "docker rm -vf $cid > /dev/null" EXIT
28+
29+
_request() {
30+
local method="$1"
31+
shift
32+
33+
local proto="$1"
34+
shift
35+
36+
local url="${1#/}"
37+
shift
38+
39+
if [ "$(docker inspect -f '{{.State.Running}}' "$cid" 2>/dev/null)" != 'true' ]; then
40+
echo >&2 "$image stopped unexpectedly!"
41+
( set -x && docker logs "$cid" ) >&2 || true
42+
false
43+
fi
44+
45+
docker run --rm \
46+
--link "$cid":nginx \
47+
"$clientImage" \
48+
nc -w 1 nginx 80
49+
}
50+
51+
. "$HOME/oi/test/retry.sh" '[ "$(_request GET / --output /dev/null || echo $?)" != 7 ]'
52+
53+
# Check that we can request /
54+
_request GET http '/templates' | grep 'example.com - OK'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
server {
2+
listen 80;
3+
return "${NGINX_MY_SERVER_NAME} - OK\n";
4+
}

0 commit comments

Comments
 (0)