Skip to content

Commit 5469bc0

Browse files
committed
[tests] add image testing
Signed-off-by: Maxim Eryomenko <[email protected]>
1 parent 68349a3 commit 5469bc0

File tree

7 files changed

+40
-19
lines changed

7 files changed

+40
-19
lines changed

.github/workflows/dockerimage.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ jobs:
1919
run: docker build . -t build
2020
- name: Testing image
2121
shell: bash
22+
working-directory: tests
2223
run: |
23-
docker run -d -p 8080:80 build
24-
./tests/test.sh
24+
docker build . -t test
25+
docker run -d -p 8080:80 test
26+
./test.sh
2527
docker stop $(docker ps -aq)
2628
- name: Push the Docker image
2729
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')

README.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
# ngxjs
22
This nginx container with support modules njs and Brotli, also use BoringSSL instead OpenSSL.
33

4-
## Testing
5-
6-
```bash
7-
$ docker run -p 8080:80 ngxjs:v0.0.2
8-
$ ./tests/test.sh
9-
10-
Test passed!
11-
```
12-
134
## Usage
145

156
In your Dockerfile just use in `FROM` directive and `COPY` your assets to `/usr/share/nginx/html` folder.

nginx.conf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ http {
2525
application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype
2626
application/x-font-ttf application/x-javascript application/xhtml+xml application/xml
2727
font/eot font/opentype font/otf font/truetype image/svg+xml image/vnd.microsoft.icon
28-
image/x-icon image/x-win-bitmap text/css text/javascript text/plain text/xml;
28+
image/x-icon image/x-win-bitmap text/css text/javascript text/plain text/xml
29+
image/bmp image/png image/gif image/jpeg image/jpg;
2930

3031
brotli on;
3132
brotli_comp_level 6;
3233
brotli_types application/atom+xml application/javascript application/json application/rss+xml
3334
application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype
3435
application/x-font-ttf application/x-javascript application/xhtml+xml application/xml
3536
font/eot font/opentype font/otf font/truetype image/svg+xml image/vnd.microsoft.icon
36-
image/x-icon image/x-win-bitmap text/css text/javascript text/plain text/xml;
37+
image/x-icon image/x-win-bitmap text/css text/javascript text/plain text/xml
38+
image/bmp image/png image/gif image/jpeg image/jpg;
3739

3840
server {
3941
listen 80;

tests/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM build
2+
3+
COPY assets /usr/share/nginx/html
4+
5+
EXPOSE 80
6+
7+
ENTRYPOINT [ "nginx", "-g", "daemon off;" ]

tests/assets/image.jpg

4.64 MB
Loading

tests/expected_image.jpg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
assets/image.jpg

tests/test.sh

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,51 @@ DIR=$(dirname "$0")
66

77
basic_case () {
88
curl http://$host:8080 > $DIR/basic_case.html
9-
check "basic_case"
9+
check "basic_case.html"
1010
}
1111

1212
gzip_case () {
1313
curl -sH 'Accept-encoding: gzip' http://$host:8080 | gunzip - > $DIR/gzip.html
14-
check "gzip"
14+
check "gzip.html"
1515
}
1616

1717
brotli_case () {
1818
curl -sH 'Accept-encoding: br' http://$host:8080 | brotli --decompress - > $DIR/brotli.html
19-
check "brotli"
19+
check "brotli.html"
20+
}
21+
22+
basic_image_case () {
23+
curl http://$host:8080/image.jpg > $DIR/image.jpg
24+
check "image.jpg"
25+
}
26+
27+
gzip_image_case () {
28+
curl -sH 'Accept-encoding: gzip' http://$host:8080/image.jpg | gunzip - > $DIR/image.jpg
29+
check "image.jpg"
30+
}
31+
32+
brotli_image_case () {
33+
curl -sH 'Accept-encoding: br' http://$host:8080/image.jpg | brotli --decompress - > $DIR/image.jpg
34+
check "image.jpg"
2035
}
2136

2237
check () {
23-
if [ -z `diff $DIR/$1.html $DIR/expected_$1.html` ]; then
24-
rm $DIR/$1.html
38+
if [ -z `diff $DIR/$1 $DIR/expected_$1` ]; then
39+
rm $DIR/$1
2540
return
2641
fi
2742

28-
rm $DIR/$1.html
43+
rm $DIR/$1
2944
echo -e "\n\e[31mTest" $1 "failed!\e[0m\n"
3045
exit 1
3146
}
3247

3348
basic_case
3449
gzip_case
3550
brotli_case
51+
basic_image_case
52+
gzip_image_case
53+
brotli_image_case
3654

3755
echo -e "\n\e[32mTests passed!\e[0m\n"
3856
exit 0

0 commit comments

Comments
 (0)