This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 8bb5adc test: introducing ---exec & --- stdin section to run cmd
(#5460)
8bb5adc is described below
commit 8bb5adcb66b69c1deab6dd53b4bec19c28b0fd7a
Author: Bisakh <[email protected]>
AuthorDate: Wed Nov 10 06:51:57 2021 +0530
test: introducing ---exec & --- stdin section to run cmd (#5460)
---
t/APISIX.pm | 32 +++++++++++++++++++
t/node/grpc-proxy-mtls.t | 40 +++--------------------
t/node/grpc-proxy-stream.t | 63 ++++--------------------------------
t/node/grpc-proxy-unary.t | 79 +++++-----------------------------------------
4 files changed, 50 insertions(+), 164 deletions(-)
diff --git a/t/APISIX.pm b/t/APISIX.pm
index 1f0f18a..43dbf92 100644
--- a/t/APISIX.pm
+++ b/t/APISIX.pm
@@ -301,6 +301,38 @@ _EOC_
$block->set_value("config", $config)
}
+ # handling shell exec in test Nginx
+ my $exec_snippet = $block->exec;
+ if ($exec_snippet) {
+ # capture the stdin & max response size
+ my $stdin = "nil";
+ if ($block->stdin) {
+ $stdin = '"' . $block->stdin . '"';
+ }
+ chomp $exec_snippet;
+ chomp $stdin;
+
+ my $max_size = $block->max_size // 8096;
+ $block->set_value("request", "GET /exec_request");
+
+ my $config = $block->config // '';
+ $config .= <<_EOC_;
+ location /exec_request {
+ content_by_lua_block {
+ local shell = require("resty.shell")
+ local ok, stdout, stderr, reason, status = shell.run([[
$exec_snippet ]], $stdin, @{[$timeout*1000]}, $max_size)
+ if not ok then
+ ngx.log(ngx.WARN, "failed to execute the script with
status: " .. status .. ", reason: " .. reason .. ", stderr: " .. stderr)
+ return
+ end
+ ngx.print(stdout)
+ }
+ }
+_EOC_
+
+ $block->set_value("config", $config)
+ }
+
my $stream_enable = $block->stream_enable;
my $stream_conf_enable = $block->stream_conf_enable;
my $extra_stream_config = $block->extra_stream_config // '';
diff --git a/t/node/grpc-proxy-mtls.t b/t/node/grpc-proxy-mtls.t
index 8640993..3c974fe 100644
--- a/t/node/grpc-proxy-mtls.t
+++ b/t/node/grpc-proxy-mtls.t
@@ -62,24 +62,8 @@ routes:
"127.0.0.1:50053": 1
type: roundrobin
#END
---- config
- location /t {
- content_by_lua_block {
- local ngx_pipe = require("ngx.pipe")
- local proc, err = ngx_pipe.spawn("grpcurl -import-path
./t/grpc_server_example/proto -proto helloworld.proto -plaintext -d
'{\"name\":\"apisix\"}' 127.0.0.1:1984 helloworld.Greeter.SayHello")
- if not proc then
- ngx.say(err)
- return
- end
- local data, err = proc:stdout_read_all()
- if not data then
- ngx.say(err)
- return
- end
- ngx.say(data:sub(1, -2))
- return
- }
- }
+--- exec
+grpcurl -import-path ./t/grpc_server_example/proto -proto helloworld.proto
-plaintext -d '{"name":"apisix"}' 127.0.0.1:1984 helloworld.Greeter.SayHello
--- response_body
{
"message": "Hello apisix"
@@ -107,24 +91,8 @@ routes:
"127.0.0.1:50053": 1
type: roundrobin
#END
---- config
- location /t {
- content_by_lua_block {
- local ngx_pipe = require("ngx.pipe")
- local proc, err = ngx_pipe.spawn("grpcurl -import-path
./t/grpc_server_example/proto -proto helloworld.proto -plaintext -d
'{\"name\":\"apisix\"}' 127.0.0.1:1984
helloworld.Greeter.SayHelloBidirectionalStream")
- if not proc then
- ngx.say(err)
- return
- end
- local data, err = proc:stdout_read_all()
- if not data then
- ngx.say(err)
- return
- end
- ngx.say(data:sub(1, -2))
- return
- }
- }
+--- exec
+grpcurl -import-path ./t/grpc_server_example/proto -proto helloworld.proto
-plaintext -d '{"name":"apisix"}' 127.0.0.1:1984
helloworld.Greeter.SayHelloBidirectionalStream
--- response_body
{
"message": "Hello apisix"
diff --git a/t/node/grpc-proxy-stream.t b/t/node/grpc-proxy-stream.t
index 21100d8..1f10b9a 100644
--- a/t/node/grpc-proxy-stream.t
+++ b/t/node/grpc-proxy-stream.t
@@ -50,27 +50,8 @@ routes:
"127.0.0.1:50051": 1
type: roundrobin
#END
---- config
- location /t {
- content_by_lua_block {
- local ngx_pipe = require("ngx.pipe")
- local opts = {
- merge_stderr = true
- }
- local proc, err = ngx_pipe.spawn("grpcurl -import-path
./t/grpc_server_example/proto -proto helloworld.proto -plaintext -d
'{\"name\":\"apisix\"}' 127.0.0.1:1984
helloworld.Greeter.SayHelloServerStream", opts)
- if not proc then
- ngx.say(err)
- return
- end
- local data, err = proc:stdout_read_all()
- if not data then
- ngx.say(err)
- return
- end
- ngx.say(data:sub(1, -2))
- return
- }
- }
+--- exec
+grpcurl -import-path ./t/grpc_server_example/proto -proto helloworld.proto
-plaintext -d '{"name":"apisix"}' 127.0.0.1:1984
helloworld.Greeter.SayHelloServerStream
--- response_body
{
"message": "Hello apisix"
@@ -107,24 +88,8 @@ routes:
"127.0.0.1:50051": 1
type: roundrobin
#END
---- config
- location /t {
- content_by_lua_block {
- local ngx_pipe = require("ngx.pipe")
- local proc, err = ngx_pipe.spawn("grpcurl -import-path
./t/grpc_server_example/proto -proto helloworld.proto -plaintext -d
'{\"name\":\"apisix\"} {\"name\":\"apisix\"} {\"name\":\"apisix\"}
{\"name\":\"apisix\"}' 127.0.0.1:1984 helloworld.Greeter.SayHelloClientStream")
- if not proc then
- ngx.say(err)
- return
- end
- local data, err = proc:stdout_read_all()
- if not data then
- ngx.say(err)
- return
- end
- ngx.say(data:sub(1, -2))
- return
- }
- }
+--- exec
+grpcurl -import-path ./t/grpc_server_example/proto -proto helloworld.proto
-plaintext -d '{"name":"apisix"} {"name":"apisix"} {"name":"apisix"}
{"name":"apisix"}' 127.0.0.1:1984 helloworld.Greeter.SayHelloClientStream
--- response_body
{
"message": "Hello apisix!Hello apisix!Hello apisix!Hello apisix!"
@@ -149,24 +114,8 @@ routes:
"127.0.0.1:50051": 1
type: roundrobin
#END
---- config
- location /t {
- content_by_lua_block {
- local ngx_pipe = require("ngx.pipe")
- local proc, err = ngx_pipe.spawn("grpcurl -import-path
./t/grpc_server_example/proto -proto helloworld.proto -plaintext -d
'{\"name\":\"apisix\"} {\"name\":\"apisix\"} {\"name\":\"apisix\"}
{\"name\":\"apisix\"}' 127.0.0.1:1984
helloworld.Greeter.SayHelloBidirectionalStream")
- if not proc then
- ngx.say(err)
- return
- end
- local data, err = proc:stdout_read_all()
- if not data then
- ngx.say(err)
- return
- end
- ngx.say(data:sub(1, -2))
- return
- }
- }
+--- exec
+grpcurl -import-path ./t/grpc_server_example/proto -proto helloworld.proto
-plaintext -d '{"name":"apisix"} {"name":"apisix"} {"name":"apisix"}
{"name":"apisix"}' 127.0.0.1:1984 helloworld.Greeter.SayHelloBidirectionalStream
--- response_body
{
"message": "Hello apisix"
diff --git a/t/node/grpc-proxy-unary.t b/t/node/grpc-proxy-unary.t
index 330b9b4..393016d 100644
--- a/t/node/grpc-proxy-unary.t
+++ b/t/node/grpc-proxy-unary.t
@@ -50,26 +50,8 @@ routes:
"127.0.0.1:50051": 1
type: roundrobin
#END
---- config
- location /t {
- content_by_lua_block {
- local ngx_pipe = require("ngx.pipe")
- local opts= {
- merge_stderr = true,
- }
- local proc, err = ngx_pipe.spawn("grpcurl -import-path
./t/grpc_server_example/proto -proto helloworld.proto -plaintext -d
'{\"name\":\"apisix\"}' 127.0.0.1:1984 helloworld.Greeter.SayHello", opts)
- if not proc then
- ngx.say(err)
- return
- end
- local data, err = proc:stdout_read_all()
- if not data then
- ngx.say(err)
- return
- end
- ngx.say(data:sub(1, -2))
- }
- }
+--- exec
+grpcurl -import-path ./t/grpc_server_example/proto -proto helloworld.proto
-plaintext -d '{"name":"apisix"}' 127.0.0.1:1984 helloworld.Greeter.SayHello
--- response_body
{
"message": "Hello apisix"
@@ -94,23 +76,8 @@ routes:
"127.0.0.1:50051": 1
type: roundrobin
#END
---- config
- location /t {
- content_by_lua_block {
- local ngx_pipe = require("ngx.pipe")
- local proc, err = ngx_pipe.spawn("grpcurl -import-path
./t/grpc_server_example/proto -proto helloworld.proto -plaintext -d
'{\"name\":\"apisix\"}' 127.0.0.1:1984 helloworld.Greeter.SayHello")
- if not proc then
- ngx.say(err)
- return
- end
- local data, err = proc:stdout_read_all()
- if not data then
- ngx.say(err)
- return
- end
- ngx.say(data:sub(1, -2))
- }
- }
+--- exec
+grpcurl -import-path ./t/grpc_server_example/proto -proto helloworld.proto
-plaintext -d '{"name":"apisix"}' 127.0.0.1:1984 helloworld.Greeter.SayHello
--- response_body
{
"message": "Hello apisix"
@@ -135,23 +102,8 @@ routes:
"127.0.0.1:50052": 1
type: roundrobin
#END
---- config
- location /t {
- content_by_lua_block {
- local ngx_pipe = require("ngx.pipe")
- local proc, err = ngx_pipe.spawn("grpcurl -import-path
./t/grpc_server_example/proto -proto helloworld.proto -plaintext -d
'{\"name\":\"apisix\"}' 127.0.0.1:1984 helloworld.Greeter.SayHello")
- if not proc then
- ngx.say(err)
- return
- end
- local data, err = proc:stdout_read_all()
- if not data then
- ngx.say(err)
- return
- end
- ngx.say(data:sub(1, -2))
- }
- }
+--- exec
+grpcurl -import-path ./t/grpc_server_example/proto -proto helloworld.proto
-plaintext -d '{"name":"apisix"}' 127.0.0.1:1984 helloworld.Greeter.SayHello
--- response_body
{
"message": "Hello apisix"
@@ -182,23 +134,8 @@ routes:
"127.0.0.1:50051": 1
type: roundrobin
#END
---- config
- location /t {
- content_by_lua_block {
- local ngx_pipe = require("ngx.pipe")
- local proc, err = ngx_pipe.spawn("grpcurl -import-path
./t/grpc_server_example/proto -proto helloworld.proto -insecure -d
'{\"name\":\"apisix\"}' test.com:1994 helloworld.Greeter.SayHello")
- if not proc then
- ngx.say(err)
- return
- end
- local data, err = proc:stdout_read_all()
- if not data then
- ngx.say(err)
- return
- end
- ngx.say(data:sub(1, -2))
- }
- }
+--- exec
+grpcurl -import-path ./t/grpc_server_example/proto -proto helloworld.proto
-insecure -d '{"name":"apisix"}' test.com:1994 helloworld.Greeter.SayHello
--- response_body
{
"message": "Hello apisix"