Skip to content

Commit

Permalink
test: remove duplicate proto unit test file and tweak test case tit…
Browse files Browse the repository at this point in the history
…le (apache#9445)
  • Loading branch information
kayx23 authored May 11, 2023
1 parent 2494b18 commit 4df6723
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 217 deletions.
216 changes: 0 additions & 216 deletions t/admin/proto.t

This file was deleted.

141 changes: 140 additions & 1 deletion t/admin/protos.t
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ run_tests;

__DATA__
=== TEST 1: test /apisix/admin/protos/{id}
=== TEST 1: put proto (id:1)
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -75,3 +75,142 @@ __DATA__
}
--- response_body
[put proto] code: 201 message: passed
=== TEST 2: delete proto(id:1)
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, message = t('/apisix/admin/protos/1',
ngx.HTTP_DELETE
)
if code ~= 200 then
ngx.status = code
ngx.say("[delete proto] code: ", code, " message: ", message)
return
end
ngx.say("[delete proto] code: ", code, " message: ", message)
}
}
--- response_body
[delete proto] code: 200 message: passed
=== TEST 3: put proto (id:2) + route refer proto(proto id 2) + delete proto(proto id 2)
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, message = t('/apisix/admin/protos/2',
ngx.HTTP_PUT,
[[{
"content": "syntax = \"proto3\";
package proto;
message HelloRequest{
string name = 1;
}
message HelloResponse{
int32 code = 1;
string msg = 2;
}
// The greeting service definition.
service Hello {
// Sends a greeting
rpc SayHi (HelloRequest) returns (HelloResponse){}
}"
}]]
)
if code ~= 201 then
ngx.status = code
ngx.say("[put proto] code: ", code, " message: ", message)
return
end
ngx.say("[put proto] code: ", code, " message: ", message)
code, message = t('/apisix/admin/routes/2',
ngx.HTTP_PUT,
[[{
"methods": ["GET"],
"plugins": {
"grpc-transcode": {
"_meta": {
"disable": false
},
"method": "SayHi",
"proto_id": 2,
"service": "proto.Hello"
}
},
"upstream": {
"nodes": {
"127.0.0.1:8080": 1
},
"type": "roundrobin"
},
"uri": "/grpc/sayhi",
"name": "hi-grpc"
}]]
)
if code ~= 201 then
ngx.status = code
ngx.say("[route refer proto] code: ", code, " message: ", message)
return
end
ngx.say("[route refer proto] code: ", code, " message: ", message)
ngx.sleep(0.1) -- ensure reference is synced from etcd
code, message = t('/apisix/admin/protos/2',
ngx.HTTP_DELETE
)
ngx.say("[delete proto] code: ", code)
}
}
--- response_body
[put proto] code: 201 message: passed
[route refer proto] code: 201 message: passed
[delete proto] code: 400
=== TEST 4: reject invalid proto
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, message = t('/apisix/admin/protos/1',
ngx.HTTP_PUT,
[[{
"content": "syntax = \"proto3\";
package proto;
message HelloRequest{
string name = 1;
}
message HelloResponse{
int32 code = 1;
string msg = 1;
}"
}]]
)
if code ~= 200 then
ngx.status = code
end
ngx.say(message)
}
}
--- error_code: 400
--- response_body eval
qr/invalid content:/

0 comments on commit 4df6723

Please sign in to comment.