Skip to content

Commit

Permalink
t
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <spacewanderlzx@gmail.com>
  • Loading branch information
spacewander committed Jul 2, 2021
1 parent 6190097 commit 8d4a88a
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 117 deletions.
24 changes: 7 additions & 17 deletions t/APISIX.pm
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ _EOC_
my $stream_enable = $block->stream_enable;
my $stream_conf_enable = $block->stream_conf_enable;
my $extra_stream_config = $block->extra_stream_config // '';
my $stream_upstream_code = $block->stream_upstream_code // <<_EOC_;
local sock = ngx.req.socket()
local data = sock:receive("1")
ngx.say("hello world")
_EOC_

my $stream_config = $block->stream_config // <<_EOC_;
$lua_deps_path
lua_socket_log_errors off;
Expand Down Expand Up @@ -339,9 +345,7 @@ _EOC_
listen 1995;
content_by_lua_block {
local sock = ngx.req.socket()
local data = sock:receive("1")
ngx.say("hello world")
$stream_upstream_code
}
}
_EOC_
Expand Down Expand Up @@ -519,20 +523,6 @@ _EOC_
apisix.http_log_phase()
}
}
location = /v3/auth/authenticate {
content_by_lua_block {
ngx.log(ngx.WARN, "etcd auth failed!")
}
}
location = /.well-known/openid-configuration {
content_by_lua_block {
local t = require("lib.test_admin")
local openid_data = t.read_file("t/plugin/openid-configuration.json")
ngx.say(openid_data)
}
}
}
$a6_ngx_directives
Expand Down
14 changes: 13 additions & 1 deletion t/lib/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ end

function _M.go()
local action = string.sub(ngx.var.uri, 2)
action = string.gsub(action, "[/\\.]", "_")
action = string.gsub(action, "[/\\.-]", "_")
if not action or not _M[action] then
return ngx.exit(404)
end
Expand Down Expand Up @@ -418,4 +418,16 @@ function _M.server_error()
end


function _M.v3_auth_authenticate()
ngx.log(ngx.WARN, "etcd auth failed!")
end


function _M._well_known_openid_configuration()
local t = require("lib.test_admin")
local openid_data = t.read_file("t/plugin/openid-configuration.json")
ngx.say(openid_data)
end


return _M
123 changes: 58 additions & 65 deletions t/plugin/traffic-split.t
Original file line number Diff line number Diff line change
Expand Up @@ -614,41 +614,38 @@ GET /t
--- config
location /t {
content_by_lua_block {
local json = require("toolkit.json")
local t = require("lib.test_admin").test
local data = {
uri = "/server_port",
plugins = {
["traffic-split"] = {
rules = { {
weighted_upstreams = { {
upstream = {
name = "upstream_A",
type = "roundrobin",
nodes = {
["foo.com:80"] = 0
}
},
weight = 2
}, {
weight = 1
} }
} }
}
},
upstream = {
type = "roundrobin",
nodes = {
["127.0.0.1:1980"] = 1
}
}
}
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"uri": "/server_port",
"plugins": {
"traffic-split": {
"rules": [
{
"weighted_upstreams": [
{
"upstream": {
"name": "upstream_A",
"type": "roundrobin",
"nodes": {
"foo.com:80": 0
}
},
"weight": 2
},
{
"weight": 1
}
]
}
]
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 1
}
}
}]]
json.encode(data)
)
if code >= 300 then
ngx.status = code
Expand Down Expand Up @@ -756,42 +753,38 @@ GET /t
--- config
location /t {
content_by_lua_block {
local json = require("toolkit.json")
local t = require("lib.test_admin").test
local data = {
uri = "/server_port",
plugins = {
["traffic-split"] = {
rules = { {
match = { {
vars = { { "http_release", "==", "blue" } }
} },
weighted_upstreams = { {
upstream = {
name = "upstream_A",
type = "roundrobin",
nodes = {
["127.0.0.1:1981"] = 1
}
}
} }
} }
}
},
upstream = {
type = "roundrobin",
nodes = {
["127.0.0.1:1980"] = 1
}
}
}
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[=[{
"uri": "/server_port",
"plugins": {
"traffic-split": {
"rules": [
{
"match": [
{
"vars": [["http_release","==","blue"]]
}
],
"weighted_upstreams": [
{
"upstream": {
"name": "upstream_A",
"type": "roundrobin",
"nodes": {
"127.0.0.1:1981":1
}
}
}
]
}
]
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 1
}
}
}]=]
json.encode(data)
)
if code >= 300 then
ngx.status = code
Expand Down
64 changes: 30 additions & 34 deletions t/plugin/traffic-split2.t
Original file line number Diff line number Diff line change
Expand Up @@ -179,43 +179,39 @@ x-real-ip: 127.0.0.1
--- config
location /t {
content_by_lua_block {
local json = require("toolkit.json")
local t = require("lib.test_admin").test
local data = {
uri = "/uri",
plugins = {
["traffic-split"] = {
rules = { {
match = { {
vars = { { "arg_name", "==", "jack" } }
} },
weighted_upstreams = { {
upstream = {
type = "roundrobin",
pass_host = "rewrite",
upstream_host = "test.com",
nodes = {
["127.0.0.1:1981"] = 1
}
}
} }
} }
}
},
upstream = {
type = "roundrobin",
nodes = {
["127.0.0.1:1980"] = 1
}
}
}
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PATCH,
[=[{
"uri": "/uri",
"plugins": {
"traffic-split": {
"rules": [
{
"match": [
{
"vars": [["arg_name", "==", "jack"]]
}
],
"weighted_upstreams": [
{
"upstream": {
"type": "roundrobin",
"pass_host": "rewrite",
"upstream_host": "test.com",
"nodes": {
"127.0.0.1:1981":1
}
}
}
]
}
]
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 1
}
}
}]=]
json.encode(data)
)
if code >= 300 then
ngx.status = code
Expand Down
8 changes: 8 additions & 0 deletions t/stream-plugin/limit-conn.t
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ add_block_preprocessor(sub {
_EOC_

$block->set_value("config", $config);

my $stream_upstream_code = $block->stream_upstream_code // <<_EOC_;
local sock = ngx.req.socket()
local data = sock:receive("1")
ngx.sleep(0.2)
ngx.say("hello world")
_EOC_
$block->set_value("stream_upstream_code", $stream_upstream_code);
});

run_tests;
Expand Down

0 comments on commit 8d4a88a

Please sign in to comment.