Skip to content

Commit 0978251

Browse files
committed
test: integration tests for example modules
1 parent 19c094b commit 0978251

File tree

5 files changed

+307
-1
lines changed

5 files changed

+307
-1
lines changed

.github/workflows/modules.yaml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Modules
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_CMD: |
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+
nginx-ref:
33+
- master
34+
# stable-1.26
35+
36+
env:
37+
TEST_NGINX_BINARY: ${{ github.workspace }}/nginx/objs/nginx
38+
TEST_NGINX_MODULES: ${{ github.workspace }}/nginx/objs
39+
40+
steps:
41+
- uses: actions/checkout@v4
42+
- uses: actions/checkout@v4
43+
with:
44+
ref: ${{ matrix.nginx-ref }}
45+
repository: 'nginx/nginx'
46+
path: 'nginx'
47+
- uses: actions/checkout@v4
48+
with:
49+
repository: 'nginx/nginx-tests'
50+
path: 'nginx/tests'
51+
sparse-checkout: |
52+
lib
53+
54+
- uses: dtolnay/rust-toolchain@stable
55+
56+
- uses: actions/cache@v4
57+
with:
58+
path: |
59+
~/.cargo/bin/
60+
~/.cargo/registry/index/
61+
~/.cargo/registry/cache/
62+
~/.cargo/git/db/
63+
nginx/objs/ngx_rust_examples
64+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
65+
restore-keys: ${{ runner.os }}-cargo-
66+
67+
- name: configure nginx
68+
working-directory: nginx
69+
run: |
70+
${NGX_CONFIGURE_CMD} \
71+
--add-dynamic-module=${{ github.workspace }}/examples
72+
73+
- name: build nginx
74+
working-directory: nginx
75+
run: make
76+
77+
- name: run tests
78+
run: prove -r -v -I nginx/tests/lib examples/t

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: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
load_module $ENV{TEST_NGINX_MODULES}/ngx_http_awssigv4_module.so;
30+
31+
daemon off;
32+
33+
events {
34+
}
35+
36+
http {
37+
%%TEST_GLOBALS_HTTP%%
38+
39+
server {
40+
listen 127.0.0.1:8080;
41+
server_name localhost;
42+
43+
awssigv4_access_key my-access-key;
44+
awssigv4_secret_key my-secret-key;
45+
awssigv4_s3_bucket my-bucket;
46+
awssigv4_s3_endpoint s3.example.com;
47+
48+
location / {
49+
awssigv4 on;
50+
proxy_pass http://127.0.0.1:8081;
51+
}
52+
}
53+
54+
server {
55+
listen 127.0.0.1:8081;
56+
server_name localhost;
57+
58+
add_header x-amz-date \$http_x_amz_date;
59+
add_header x-authorization \$http_authorization;
60+
61+
location / { }
62+
}
63+
}
64+
65+
EOF
66+
67+
$t->write_file('index.html', '');
68+
$t->run();
69+
70+
###############################################################################
71+
72+
like(http_get('/'), qr/x-authorization: AWS4.*Credential=my-access-key/i,
73+
'awssig header');
74+
75+
###############################################################################

examples/t/curl.t

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
load_module $ENV{TEST_NGINX_MODULES}/ngx_http_curl_module.so;
30+
31+
daemon off;
32+
33+
events {
34+
}
35+
36+
http {
37+
%%TEST_GLOBALS_HTTP%%
38+
39+
server {
40+
listen 127.0.0.1:8080;
41+
server_name localhost;
42+
43+
location / {
44+
curl on;
45+
}
46+
}
47+
}
48+
49+
EOF
50+
51+
$t->write_file('index.html', '');
52+
$t->run();
53+
54+
###############################################################################
55+
56+
like(get('/', 'curl/1.2.3'), qr/403 Forbidden/, 'curl UA forbidden');
57+
like(get('/', 'MSIE 6.0'), qr/200 OK/, 'other UA allowed');
58+
59+
###############################################################################
60+
61+
sub get {
62+
my ($url, $ua, $extra) = @_;
63+
return http(<<EOF);
64+
GET $url HTTP/1.1
65+
Host: localhost
66+
Connection: close
67+
User-Agent: $ua
68+
69+
EOF
70+
}
71+
72+
###############################################################################

examples/t/upstream.t

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
load_module $ENV{TEST_NGINX_MODULES}/ngx_http_upstream_custom_module.so;
30+
31+
daemon off;
32+
33+
events {
34+
}
35+
36+
http {
37+
%%TEST_GLOBALS_HTTP%%
38+
39+
upstream u {
40+
server 127.0.0.1:8081;
41+
custom 32;
42+
}
43+
44+
server {
45+
listen 127.0.0.1:8080;
46+
server_name localhost;
47+
48+
error_log %%TESTDIR%%/e_debug.log debug;
49+
50+
location / {
51+
proxy_pass http://u;
52+
}
53+
}
54+
55+
server {
56+
listen 127.0.0.1:8081;
57+
server_name localhost;
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/200 OK/, 'custom upstream');
71+
72+
$t->stop();
73+
74+
SKIP: {
75+
skip "no --with-debug", 1 unless $t->has_module('--with-debug');
76+
77+
like($t->read_file('e_debug.log'), qr/CUSTOM UPSTREAM request/,
78+
'log - custom upstream');
79+
}
80+
81+
###############################################################################

0 commit comments

Comments
 (0)