Skip to content

Commit

Permalink
tests(proxy-wasm/assemblyscript) test cases for the SDK example filters
Browse files Browse the repository at this point in the history
  • Loading branch information
casimiro committed Nov 16, 2023
1 parent e22d5a7 commit 86da446
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 0 deletions.
141 changes: 141 additions & 0 deletions t/03-proxy_wasm/sdks/003-assemblyscript_sdk.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# vim:set ft= ts=4 sts=4 sw=4 et fdm=marker:

use strict;
use lib '.';
use t::TestWasm;

skip_valgrind('wasmtime');
skip_no_nodejs();

plan tests => repeat_each() * (blocks() * 5);

run_tests();

__DATA__
=== TEST 1: proxy_wasm AssemblyScript SDK - addheader example
--- load_nginx_modules: ngx_http_echo_module
--- wasm_modules: assemblyscript_addheader
--- config
location /t {
proxy_wasm assemblyscript_addheader 'wasm';
echo ok;
}
--- response_body
ok
--- response_headers
hello: wasm
--- no_error_log
[error]
[crit]
=== TEST 2: proxy_wasm AssemblyScript SDK - auth example, authorized
--- load_nginx_modules: ngx_http_echo_module
--- wasm_modules: assemblyscript_auth
--- tcp_listen: 12345
--- tcp_reply eval
sub {
return ["HTTP/1.1 200 OK\r\n",
"Connection: close\r\n",
"Content-Length: 0\r\n",
"\r\n"];
}
--- config
location /t {
proxy_wasm assemblyscript_auth '127.0.0.1:12345';
echo ok;
}
--- response_body
ok
--- response_headers
hello: wasm!
--- no_error_log
[error]
[crit]
=== TEST 3: proxy_wasm AssemblyScript SDK - auth example, unauthorized
--- load_nginx_modules: ngx_http_echo_module
--- wasm_modules: assemblyscript_auth
--- tcp_listen: 12345
--- tcp_reply eval
sub {
return ["HTTP/1.1 401 Unauthorized\r\n",
"Connection: close\r\n",
"Content-Length: 0\r\n",
"\r\n"];
}
--- config
location /t {
proxy_wasm assemblyscript_auth '127.0.0.1:12345';
echo ok;
}
--- error_code: 401
--- no_error_log
[error]
[crit]
[emerg]
[stub]
=== TEST 4: proxy_wasm AssemblyScript SDK - remove_headers example
--- load_nginx_modules: ngx_http_echo_module
--- wasm_modules: assemblyscript_remove_headers
--- http_config
upstream test_upstream {
server unix:$TEST_NGINX_UNIX_SOCKET;
}
server {
listen unix:$TEST_NGINX_UNIX_SOCKET;
location / {
add_header foo bar;
echo ok;
}
}
--- config
location /t {
proxy_wasm assemblyscript_remove_headers 'foo';
proxy_pass http://test_upstream/;
}
--- response_body
ok
--- raw_response_headers_unlike: foo: bar
--- no_error_log
[error]
[crit]
=== TEST 5: proxy_wasm AssemblyScript SDK - singleton example
--- load_nginx_modules: ngx_http_echo_module
--- wasm_modules: assemblyscript_remove_headers
--- http_config
upstream test_upstream {
server unix:$TEST_NGINX_UNIX_SOCKET;
}
server {
listen unix:$TEST_NGINX_UNIX_SOCKET;
location / {
add_header foo bar;
echo ok;
}
}
--- config
location /t {
proxy_wasm assemblyscript_remove_headers 'foo';
proxy_pass http://test_upstream/;
}
--- response_body
ok
--- raw_response_headers_unlike: foo: bar
--- no_error_log
[error]
[crit]
8 changes: 8 additions & 0 deletions t/TestWasm.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ our @EXPORT = qw(
skip_no_ssl
skip_no_debug
skip_no_tinygo
skip_no_nodejs
skip_valgrind
);

Expand Down Expand Up @@ -83,6 +84,13 @@ sub skip_no_tinygo {
}
}

sub skip_no_nodejs {
my @files = glob($ENV{TEST_NGINX_CRATES_DIR} . '/assemblyscript_*.wasm');
if (!@files && !defined($ENV{CI})) {
plan(skip_all => "Missing AssemblyScript .wasm bytecode files in $ENV{TEST_NGINX_CRATES_DIR}");
}
}

sub load_nginx_modules (@) {
splice @nginx_modules, 0, 0, @_;
}
Expand Down

0 comments on commit 86da446

Please sign in to comment.