Skip to content

Commit f7a2193

Browse files
committed
[check-http] add a test
1 parent a9c8bcf commit f7a2193

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

check-http/test.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/sh
2+
3+
prog=$(basename "$0")
4+
if ! [ -S /var/run/docker.sock ]
5+
then
6+
echo "$prog: there are no running docker" >&2
7+
exit 2
8+
fi
9+
10+
cd "$(dirname "$0")" || exit
11+
PATH=$(pwd):$PATH
12+
plugin=$(basename "$(pwd)")
13+
if ! which "$plugin" >/dev/null
14+
then
15+
echo "$prog: $plugin is not installed" >&2
16+
exit 2
17+
fi
18+
19+
http_port=10080
20+
http_image=httpd:2.4-bullseye
21+
proxy_port=13128
22+
proxy_image=ubuntu/squid:5.2-22.04_beta
23+
24+
halt()
25+
{
26+
docker stop "test-$plugin" "test-$plugin-proxy"
27+
docker rm "test-$plugin" "test-$plugin-proxy"
28+
docker network rm "test-$plugin-net"
29+
}
30+
31+
docker network create --driver bridge "test-$plugin-net"
32+
docker run --name "test-$plugin" \
33+
--net "test-$plugin-net" -p "$http_port:80" \
34+
-v "$(pwd)/testdata:/usr/local/apache2/htdocs/" -d "$http_image"
35+
docker run --name "test-$plugin-proxy" \
36+
--net "test-$plugin-net" -p "$proxy_port:3128" \
37+
-d "$proxy_image"
38+
trap 'halt; exit 1' 1 2 3 15
39+
sleep 10
40+
41+
status=0
42+
$plugin -u "http://localhost:$http_port/"
43+
((status+=$?))
44+
45+
# Target hostname in the URL will be resolved in the side of proxy container,
46+
# thus it must be container name or its ID.
47+
$plugin -u "http://test-$plugin/" --proxy="http://localhost:$proxy_port"
48+
((status+=$?))
49+
50+
halt
51+
exit "$status"

check-http/testdata/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>testpage</title>
6+
</head>
7+
<body>
8+
<h1>testpage</h1>
9+
<p>hello</p>
10+
</body>
11+
</html>

0 commit comments

Comments
 (0)