Skip to content

Commit b79cffd

Browse files
committed
test: integration tests for example modules
1 parent a4150bf commit b79cffd

File tree

5 files changed

+319
-1
lines changed

5 files changed

+319
-1
lines changed

.github/workflows/nginx.yaml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: NGINX
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
env:
10+
CARGO_TERM_COLOR: 'always'
11+
RUST_BACKTRACE: '1'
12+
NGX_CONFIGURE: |
13+
auto/configure
14+
--with-compat
15+
--with-debug
16+
--with-http_realip_module
17+
--with-http_ssl_module
18+
--with-http_v2_module
19+
--with-http_v3_module
20+
--with-stream
21+
--with-stream_realip_module
22+
--with-stream_ssl_module
23+
--with-threads
24+
25+
jobs:
26+
test:
27+
runs-on: ubuntu-latest
28+
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
module:
33+
# static
34+
- dynamic
35+
nginx-ref:
36+
# master
37+
- stable-1.26
38+
39+
steps:
40+
- uses: actions/checkout@v4
41+
- uses: actions/checkout@v4
42+
with:
43+
ref: ${{ matrix.nginx-ref }}
44+
repository: 'nginx/nginx'
45+
path: 'nginx'
46+
- uses: actions/checkout@v4
47+
with:
48+
repository: 'nginx/nginx-tests'
49+
path: 'nginx/tests'
50+
sparse-checkout: |
51+
lib
52+
53+
- uses: dtolnay/rust-toolchain@stable
54+
55+
- uses: actions/cache@v4
56+
with:
57+
path: |
58+
~/.cargo/bin/
59+
~/.cargo/registry/index/
60+
~/.cargo/registry/cache/
61+
~/.cargo/git/db/
62+
nginx/objs/ngx_rust_examples
63+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
64+
restore-keys: ${{ runner.os }}-cargo-
65+
66+
- name: Configure nginx with static modules
67+
if: matrix.module == 'static'
68+
working-directory: nginx
69+
run: |
70+
${NGX_CONFIGURE} \
71+
--add-module=${{ github.workspace }}/examples
72+
73+
- name: Configure nginx with dynamic modules
74+
if: matrix.module != 'static'
75+
working-directory: nginx
76+
env:
77+
TEST_NGINX_GLOBALS: |
78+
load_module ${{ github.workspace }}/nginx/objs/ngx_http_awssigv4_module.so;
79+
load_module ${{ github.workspace }}/nginx/objs/ngx_http_curl_module.so;
80+
load_module ${{ github.workspace }}/nginx/objs/ngx_http_upstream_custom_module.so;
81+
run: |
82+
${NGX_CONFIGURE} \
83+
--add-dynamic-module=${{ github.workspace }}/examples
84+
echo "TEST_NGINX_GLOBALS=$TEST_NGINX_GLOBALS" >> $GITHUB_ENV
85+
86+
- name: Build nginx
87+
working-directory: nginx
88+
run: make -j$(nproc)
89+
90+
- name: Run tests
91+
env:
92+
TEST_NGINX_BINARY: ${{ github.workspace }}/nginx/objs/nginx
93+
TEST_NGINX_MODULES: ${{ github.workspace }}/nginx/objs
94+
run: |
95+
prove -v -j$(nproc) -Inginx/tests/lib --state=save examples/t \
96+
|| prove -v -Inginx/tests/lib --state=failed

examples/config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if [ $HTTP = YES ]; then
2424

2525
ngx_module_lib=$NGX_OBJS/$ngx_addon_name/$ngx_cargo_profile/examples/lib$ngx_module_lib.a
2626
ngx_module_deps=$ngx_module_lib
27-
ngx_module_libs=$ngx_module_lib
27+
ngx_module_libs="$ngx_module_lib -lm"
2828

2929
# Module deps are usually added to the object file targets, but we don't have any
3030
LINK_DEPS="$LINK_DEPS $ngx_module_lib"

examples/t/awssig.t

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/perl
2+
3+
# (C) Nginx, Inc
4+
5+
# Tests for ngx-rust example modules.
6+
7+
###############################################################################
8+
9+
use warnings;
10+
use strict;
11+
12+
use Test::More;
13+
14+
BEGIN { use FindBin; chdir($FindBin::Bin); }
15+
16+
use lib 'lib';
17+
use Test::Nginx;
18+
19+
###############################################################################
20+
21+
select STDERR; $| = 1;
22+
select STDOUT; $| = 1;
23+
24+
my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(1)
25+
->write_file_expand('nginx.conf', <<"EOF");
26+
27+
%%TEST_GLOBALS%%
28+
29+
daemon off;
30+
31+
events {
32+
}
33+
34+
http {
35+
%%TEST_GLOBALS_HTTP%%
36+
37+
server {
38+
listen 127.0.0.1:8080;
39+
server_name localhost;
40+
41+
awssigv4_access_key my-access-key;
42+
awssigv4_secret_key my-secret-key;
43+
awssigv4_s3_bucket my-bucket;
44+
awssigv4_s3_endpoint s3.example.com;
45+
46+
location / {
47+
awssigv4 on;
48+
proxy_pass http://127.0.0.1:8081;
49+
}
50+
}
51+
52+
server {
53+
listen 127.0.0.1:8081;
54+
server_name localhost;
55+
56+
add_header x-amz-date \$http_x_amz_date;
57+
add_header x-authorization \$http_authorization;
58+
59+
location / { }
60+
}
61+
}
62+
63+
EOF
64+
65+
$t->write_file('index.html', '');
66+
$t->run();
67+
68+
###############################################################################
69+
70+
like(http_get('/'), qr/x-authorization: AWS4.*Credential=my-access-key/i,
71+
'awssig header');
72+
73+
###############################################################################

examples/t/curl.t

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/perl
2+
3+
# (C) Nginx, Inc
4+
5+
# Tests for ngx-rust example modules.
6+
7+
###############################################################################
8+
9+
use warnings;
10+
use strict;
11+
12+
use Test::More;
13+
14+
BEGIN { use FindBin; chdir($FindBin::Bin); }
15+
16+
use lib 'lib';
17+
use Test::Nginx;
18+
19+
###############################################################################
20+
21+
select STDERR; $| = 1;
22+
select STDOUT; $| = 1;
23+
24+
my $t = Test::Nginx->new()->has(qw/http/)->plan(2)
25+
->write_file_expand('nginx.conf', <<"EOF");
26+
27+
%%TEST_GLOBALS%%
28+
29+
daemon off;
30+
31+
events {
32+
}
33+
34+
http {
35+
%%TEST_GLOBALS_HTTP%%
36+
37+
server {
38+
listen 127.0.0.1:8080;
39+
server_name localhost;
40+
41+
location / {
42+
curl on;
43+
}
44+
}
45+
}
46+
47+
EOF
48+
49+
$t->write_file('index.html', '');
50+
$t->run();
51+
52+
###############################################################################
53+
54+
like(get('/', 'curl/1.2.3'), qr/403 Forbidden/, 'curl UA forbidden');
55+
like(get('/', 'MSIE 6.0'), qr/200 OK/, 'other UA allowed');
56+
57+
###############################################################################
58+
59+
sub get {
60+
my ($url, $ua, $extra) = @_;
61+
return http(<<EOF);
62+
GET $url HTTP/1.1
63+
Host: localhost
64+
Connection: close
65+
User-Agent: $ua
66+
67+
EOF
68+
}
69+
70+
###############################################################################

examples/t/upstream.t

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/perl
2+
3+
# (C) Nginx, Inc
4+
5+
# Tests for ngx-rust example modules.
6+
7+
###############################################################################
8+
9+
use warnings;
10+
use strict;
11+
12+
use Test::More;
13+
14+
BEGIN { use FindBin; chdir($FindBin::Bin); }
15+
16+
use lib 'lib';
17+
use Test::Nginx;
18+
19+
###############################################################################
20+
21+
select STDERR; $| = 1;
22+
select STDOUT; $| = 1;
23+
24+
my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(2)
25+
->write_file_expand('nginx.conf', <<"EOF");
26+
27+
%%TEST_GLOBALS%%
28+
29+
daemon off;
30+
31+
events {
32+
}
33+
34+
http {
35+
%%TEST_GLOBALS_HTTP%%
36+
37+
upstream u {
38+
server 127.0.0.1:8081;
39+
custom 32;
40+
}
41+
42+
server {
43+
listen 127.0.0.1:8080;
44+
server_name localhost;
45+
46+
error_log %%TESTDIR%%/e_debug.log debug;
47+
48+
location / {
49+
proxy_pass http://u;
50+
}
51+
}
52+
53+
server {
54+
listen 127.0.0.1:8081;
55+
server_name localhost;
56+
57+
location / { }
58+
}
59+
}
60+
61+
EOF
62+
63+
$t->write_file('index.html', '');
64+
$t->run();
65+
66+
###############################################################################
67+
68+
like(http_get('/'), qr/200 OK/, 'custom upstream');
69+
70+
$t->stop();
71+
72+
SKIP: {
73+
skip "no --with-debug", 1 unless $t->has_module('--with-debug');
74+
75+
like($t->read_file('e_debug.log'), qr/CUSTOM UPSTREAM request/,
76+
'log - custom upstream');
77+
}
78+
79+
###############################################################################

0 commit comments

Comments
 (0)