2019-08-21 23:10:34 +08:00
|
|
|
BEGIN {
|
|
|
|
if ($ENV{TEST_NGINX_CHECK_LEAK}) {
|
|
|
|
$SkipReason = "unavailable for the hup tests";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$ENV{TEST_NGINX_USE_HUP} = 1;
|
|
|
|
undef $ENV{TEST_NGINX_USE_STAP};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-10 09:42:55 +08:00
|
|
|
use t::APISIX 'no_plan';
|
2019-08-21 23:10:34 +08:00
|
|
|
|
|
|
|
repeat_each(1);
|
|
|
|
no_long_string();
|
|
|
|
no_shuffle();
|
|
|
|
no_root_location();
|
|
|
|
log_level('debug');
|
|
|
|
|
|
|
|
run_tests;
|
|
|
|
|
|
|
|
__DATA__
|
|
|
|
|
|
|
|
=== TEST 1: set proto(id: 1)
|
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
local code, body = t('/apisix/admin/proto/1',
|
|
|
|
ngx.HTTP_PUT,
|
|
|
|
[[{
|
|
|
|
"content" : "syntax = \"proto3\";
|
|
|
|
package helloworld;
|
|
|
|
service Greeter {
|
|
|
|
rpc SayHello (HelloRequest) returns (HelloReply) {}
|
|
|
|
}
|
|
|
|
message HelloRequest {
|
|
|
|
string name = 1;
|
|
|
|
}
|
|
|
|
message HelloReply {
|
|
|
|
string message = 1;
|
|
|
|
}"
|
|
|
|
}]]
|
|
|
|
)
|
|
|
|
|
|
|
|
if code >= 300 then
|
|
|
|
ngx.status = code
|
|
|
|
end
|
|
|
|
ngx.say(body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
passed
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 2: set routes(id: 1)
|
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
local code, body = t('/apisix/admin/routes/1',
|
|
|
|
ngx.HTTP_PUT,
|
|
|
|
[[{
|
|
|
|
"methods": ["GET"],
|
|
|
|
"uri": "/grpctest",
|
|
|
|
"service_protocol": "grpc",
|
|
|
|
"plugins": {
|
2019-08-22 14:40:56 +08:00
|
|
|
"grpc-transcode": {
|
2019-08-21 23:10:34 +08:00
|
|
|
"proto_id": "1",
|
|
|
|
"service": "helloworld.Greeter",
|
|
|
|
"method": "SayHello"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"upstream": {
|
|
|
|
"type": "roundrobin",
|
|
|
|
"nodes": {
|
|
|
|
"127.0.0.1:50051": 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}]]
|
|
|
|
)
|
|
|
|
|
|
|
|
if code >= 300 then
|
|
|
|
ngx.status = code
|
|
|
|
end
|
|
|
|
ngx.say(body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
passed
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
2019-08-22 14:40:56 +08:00
|
|
|
|
2019-08-21 23:10:34 +08:00
|
|
|
=== TEST 3: hit route
|
|
|
|
--- request
|
2019-08-24 09:13:52 +08:00
|
|
|
GET /grpctest?name=world
|
2019-08-21 23:10:34 +08:00
|
|
|
--- response_body eval
|
2019-08-24 09:13:52 +08:00
|
|
|
qr/\{"message":"Hello world"\}/
|
2019-08-21 23:10:34 +08:00
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
2019-08-22 14:40:56 +08:00
|
|
|
|
2019-08-21 23:10:34 +08:00
|
|
|
=== TEST 4: wrong service protocol
|
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
local code, body = t('/apisix/admin/routes/1',
|
|
|
|
ngx.HTTP_PUT,
|
|
|
|
[[{
|
|
|
|
"methods": ["GET"],
|
|
|
|
"uri": "/grpctest",
|
|
|
|
"service_protocol": "asf",
|
|
|
|
"plugins": {
|
2019-08-22 14:40:56 +08:00
|
|
|
"grpc-transcode": {
|
2019-08-21 23:10:34 +08:00
|
|
|
"proto_id": "1",
|
|
|
|
"service": "helloworld.Greeter",
|
|
|
|
"method": "SayHello"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"upstream": {
|
|
|
|
"type": "roundrobin",
|
|
|
|
"nodes": {
|
|
|
|
"127.0.0.1:50051": 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}]]
|
|
|
|
)
|
|
|
|
|
|
|
|
if code >= 300 then
|
|
|
|
ngx.status = code
|
|
|
|
end
|
|
|
|
ngx.say(body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- error_code: 400
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
2019-08-23 07:30:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 5: wrong upstream address
|
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
local code, body = t('/apisix/admin/routes/1',
|
|
|
|
ngx.HTTP_PUT,
|
|
|
|
[[{
|
|
|
|
"methods": ["GET"],
|
|
|
|
"uri": "/grpctest",
|
|
|
|
"service_protocol": "grpc",
|
|
|
|
"plugins": {
|
|
|
|
"grpc-transcode": {
|
|
|
|
"proto_id": "1",
|
|
|
|
"service": "helloworld.Greeter",
|
|
|
|
"method": "SayHello"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"upstream": {
|
|
|
|
"type": "roundrobin",
|
|
|
|
"nodes": {
|
|
|
|
"127.0.0.1:1970": 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}]]
|
|
|
|
)
|
|
|
|
|
|
|
|
if code >= 300 then
|
|
|
|
ngx.status = code
|
|
|
|
end
|
|
|
|
ngx.say(body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
passed
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 6: hit route (Connection refused)
|
|
|
|
--- request
|
|
|
|
GET /grpctest
|
|
|
|
--- response_body eval
|
|
|
|
qr/502 Bad Gateway/
|
|
|
|
--- error_log
|
|
|
|
Connection refused) while connecting to upstream
|
|
|
|
--- error_code: 502
|
2019-08-24 09:13:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=== TEST 7: update proto(id: 1)
|
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
local code, body = t('/apisix/admin/proto/1',
|
|
|
|
ngx.HTTP_PUT,
|
|
|
|
[[{
|
|
|
|
"content" : "syntax = \"proto3\";
|
|
|
|
package helloworld;
|
|
|
|
service Greeter {
|
|
|
|
rpc SayHello (HelloRequest) returns (HelloReply) {}
|
|
|
|
rpc Plus (PlusRequest) returns (PlusReply) {}
|
|
|
|
}
|
|
|
|
message HelloRequest {
|
|
|
|
string name = 1;
|
|
|
|
}
|
|
|
|
message HelloReply {
|
|
|
|
string message = 1;
|
|
|
|
}
|
|
|
|
message PlusRequest {
|
|
|
|
int32 a = 1;
|
|
|
|
int32 b = 2;
|
|
|
|
}
|
|
|
|
message PlusReply {
|
|
|
|
int32 result = 1;
|
|
|
|
}"
|
|
|
|
}]]
|
|
|
|
)
|
|
|
|
|
|
|
|
if code >= 300 then
|
|
|
|
ngx.status = code
|
|
|
|
end
|
|
|
|
ngx.say(body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
passed
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
2019-08-26 13:10:15 +08:00
|
|
|
|
2019-08-24 09:13:52 +08:00
|
|
|
=== TEST 8: set routes(id: 2)
|
|
|
|
--- config
|
|
|
|
location /t {
|
|
|
|
content_by_lua_block {
|
|
|
|
local t = require("lib.test_admin").test
|
|
|
|
local code, body = t('/apisix/admin/routes/2',
|
|
|
|
ngx.HTTP_PUT,
|
|
|
|
[[{
|
|
|
|
"methods": ["GET"],
|
|
|
|
"uri": "/grpc_plus",
|
|
|
|
"service_protocol": "grpc",
|
|
|
|
"plugins": {
|
|
|
|
"grpc-transcode": {
|
|
|
|
"proto_id": "1",
|
|
|
|
"service": "helloworld.Greeter",
|
|
|
|
"method": "Plus"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"upstream": {
|
|
|
|
"type": "roundrobin",
|
|
|
|
"nodes": {
|
|
|
|
"127.0.0.1:50051": 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}]]
|
|
|
|
)
|
|
|
|
|
|
|
|
if code >= 300 then
|
|
|
|
ngx.status = code
|
|
|
|
end
|
|
|
|
ngx.say(body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--- request
|
|
|
|
GET /t
|
|
|
|
--- response_body
|
|
|
|
passed
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|
|
|
|
|
|
|
|
|
2019-08-26 13:10:15 +08:00
|
|
|
|
2019-08-24 09:13:52 +08:00
|
|
|
=== TEST 9: hit route
|
|
|
|
--- request
|
|
|
|
GET /grpc_plus?a=1&b=2
|
|
|
|
--- response_body eval
|
|
|
|
qr/\{"result":3\}/
|
|
|
|
--- no_error_log
|
|
|
|
[error]
|