-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: integration tests for example modules
- Loading branch information
1 parent
a4150bf
commit b79cffd
Showing
5 changed files
with
319 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
name: NGINX | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
env: | ||
CARGO_TERM_COLOR: 'always' | ||
RUST_BACKTRACE: '1' | ||
NGX_CONFIGURE: | | ||
auto/configure | ||
--with-compat | ||
--with-debug | ||
--with-http_realip_module | ||
--with-http_ssl_module | ||
--with-http_v2_module | ||
--with-http_v3_module | ||
--with-stream | ||
--with-stream_realip_module | ||
--with-stream_ssl_module | ||
--with-threads | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
module: | ||
# static | ||
- dynamic | ||
nginx-ref: | ||
# master | ||
- stable-1.26 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ matrix.nginx-ref }} | ||
repository: 'nginx/nginx' | ||
path: 'nginx' | ||
- uses: actions/checkout@v4 | ||
with: | ||
repository: 'nginx/nginx-tests' | ||
path: 'nginx/tests' | ||
sparse-checkout: | | ||
lib | ||
- uses: dtolnay/rust-toolchain@stable | ||
|
||
- uses: actions/cache@v4 | ||
with: | ||
path: | | ||
~/.cargo/bin/ | ||
~/.cargo/registry/index/ | ||
~/.cargo/registry/cache/ | ||
~/.cargo/git/db/ | ||
nginx/objs/ngx_rust_examples | ||
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | ||
restore-keys: ${{ runner.os }}-cargo- | ||
|
||
- name: Configure nginx with static modules | ||
if: matrix.module == 'static' | ||
working-directory: nginx | ||
run: | | ||
${NGX_CONFIGURE} \ | ||
--add-module=${{ github.workspace }}/examples | ||
- name: Configure nginx with dynamic modules | ||
if: matrix.module != 'static' | ||
working-directory: nginx | ||
env: | ||
TEST_NGINX_GLOBALS: | | ||
load_module ${{ github.workspace }}/nginx/objs/ngx_http_awssigv4_module.so; | ||
load_module ${{ github.workspace }}/nginx/objs/ngx_http_curl_module.so; | ||
load_module ${{ github.workspace }}/nginx/objs/ngx_http_upstream_custom_module.so; | ||
run: | | ||
${NGX_CONFIGURE} \ | ||
--add-dynamic-module=${{ github.workspace }}/examples | ||
echo "TEST_NGINX_GLOBALS=$TEST_NGINX_GLOBALS" >> $GITHUB_ENV | ||
- name: Build nginx | ||
working-directory: nginx | ||
run: make -j$(nproc) | ||
|
||
- name: Run tests | ||
env: | ||
TEST_NGINX_BINARY: ${{ github.workspace }}/nginx/objs/nginx | ||
TEST_NGINX_MODULES: ${{ github.workspace }}/nginx/objs | ||
run: | | ||
prove -v -j$(nproc) -Inginx/tests/lib --state=save examples/t \ | ||
|| prove -v -Inginx/tests/lib --state=failed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/perl | ||
|
||
# (C) Nginx, Inc | ||
|
||
# Tests for ngx-rust example modules. | ||
|
||
############################################################################### | ||
|
||
use warnings; | ||
use strict; | ||
|
||
use Test::More; | ||
|
||
BEGIN { use FindBin; chdir($FindBin::Bin); } | ||
|
||
use lib 'lib'; | ||
use Test::Nginx; | ||
|
||
############################################################################### | ||
|
||
select STDERR; $| = 1; | ||
select STDOUT; $| = 1; | ||
|
||
my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(1) | ||
->write_file_expand('nginx.conf', <<"EOF"); | ||
%%TEST_GLOBALS%% | ||
daemon off; | ||
events { | ||
} | ||
http { | ||
%%TEST_GLOBALS_HTTP%% | ||
server { | ||
listen 127.0.0.1:8080; | ||
server_name localhost; | ||
awssigv4_access_key my-access-key; | ||
awssigv4_secret_key my-secret-key; | ||
awssigv4_s3_bucket my-bucket; | ||
awssigv4_s3_endpoint s3.example.com; | ||
location / { | ||
awssigv4 on; | ||
proxy_pass http://127.0.0.1:8081; | ||
} | ||
} | ||
server { | ||
listen 127.0.0.1:8081; | ||
server_name localhost; | ||
add_header x-amz-date \$http_x_amz_date; | ||
add_header x-authorization \$http_authorization; | ||
location / { } | ||
} | ||
} | ||
EOF | ||
|
||
$t->write_file('index.html', ''); | ||
$t->run(); | ||
|
||
############################################################################### | ||
|
||
like(http_get('/'), qr/x-authorization: AWS4.*Credential=my-access-key/i, | ||
'awssig header'); | ||
|
||
############################################################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/perl | ||
|
||
# (C) Nginx, Inc | ||
|
||
# Tests for ngx-rust example modules. | ||
|
||
############################################################################### | ||
|
||
use warnings; | ||
use strict; | ||
|
||
use Test::More; | ||
|
||
BEGIN { use FindBin; chdir($FindBin::Bin); } | ||
|
||
use lib 'lib'; | ||
use Test::Nginx; | ||
|
||
############################################################################### | ||
|
||
select STDERR; $| = 1; | ||
select STDOUT; $| = 1; | ||
|
||
my $t = Test::Nginx->new()->has(qw/http/)->plan(2) | ||
->write_file_expand('nginx.conf', <<"EOF"); | ||
%%TEST_GLOBALS%% | ||
daemon off; | ||
events { | ||
} | ||
http { | ||
%%TEST_GLOBALS_HTTP%% | ||
server { | ||
listen 127.0.0.1:8080; | ||
server_name localhost; | ||
location / { | ||
curl on; | ||
} | ||
} | ||
} | ||
EOF | ||
|
||
$t->write_file('index.html', ''); | ||
$t->run(); | ||
|
||
############################################################################### | ||
|
||
like(get('/', 'curl/1.2.3'), qr/403 Forbidden/, 'curl UA forbidden'); | ||
like(get('/', 'MSIE 6.0'), qr/200 OK/, 'other UA allowed'); | ||
|
||
############################################################################### | ||
|
||
sub get { | ||
my ($url, $ua, $extra) = @_; | ||
return http(<<EOF); | ||
GET $url HTTP/1.1 | ||
Host: localhost | ||
Connection: close | ||
User-Agent: $ua | ||
EOF | ||
} | ||
|
||
############################################################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/perl | ||
|
||
# (C) Nginx, Inc | ||
|
||
# Tests for ngx-rust example modules. | ||
|
||
############################################################################### | ||
|
||
use warnings; | ||
use strict; | ||
|
||
use Test::More; | ||
|
||
BEGIN { use FindBin; chdir($FindBin::Bin); } | ||
|
||
use lib 'lib'; | ||
use Test::Nginx; | ||
|
||
############################################################################### | ||
|
||
select STDERR; $| = 1; | ||
select STDOUT; $| = 1; | ||
|
||
my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(2) | ||
->write_file_expand('nginx.conf', <<"EOF"); | ||
%%TEST_GLOBALS%% | ||
daemon off; | ||
events { | ||
} | ||
http { | ||
%%TEST_GLOBALS_HTTP%% | ||
upstream u { | ||
server 127.0.0.1:8081; | ||
custom 32; | ||
} | ||
server { | ||
listen 127.0.0.1:8080; | ||
server_name localhost; | ||
error_log %%TESTDIR%%/e_debug.log debug; | ||
location / { | ||
proxy_pass http://u; | ||
} | ||
} | ||
server { | ||
listen 127.0.0.1:8081; | ||
server_name localhost; | ||
location / { } | ||
} | ||
} | ||
EOF | ||
|
||
$t->write_file('index.html', ''); | ||
$t->run(); | ||
|
||
############################################################################### | ||
|
||
like(http_get('/'), qr/200 OK/, 'custom upstream'); | ||
|
||
$t->stop(); | ||
|
||
SKIP: { | ||
skip "no --with-debug", 1 unless $t->has_module('--with-debug'); | ||
|
||
like($t->read_file('e_debug.log'), qr/CUSTOM UPSTREAM request/, | ||
'log - custom upstream'); | ||
} | ||
|
||
############################################################################### |