Skip to content

Commit

Permalink
test: change the string to lua table (#6632)
Browse files Browse the repository at this point in the history
  • Loading branch information
tzssangglass authored Mar 17, 2022
1 parent 210575c commit 15517fe
Show file tree
Hide file tree
Showing 4 changed files with 890 additions and 619 deletions.
265 changes: 171 additions & 94 deletions t/plugin/traffic-split.t
Original file line number Diff line number Diff line change
Expand Up @@ -397,35 +397,64 @@ GET /t
--- config
location /t {
content_by_lua_block {
local json = require("toolkit.json")
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[=[{
"uri": "/server_port",
"plugins": {
"traffic-split": {
"rules": [
local data = {
uri = "/server_port",
plugins = {
["traffic-split"] = {
rules = { {
match = {
{
"match": [
{"vars": [["arg_name", "==", "jack"], ["arg_age", "~~", "^[1-9]{1,2}"]]},
{"vars": [["arg_name2", "in", ["jack", "rose"]], ["arg_age2", "!", "<", 18]]}
],
"weighted_upstreams": [
{"upstream": {"name": "upstream_A", "type": "roundrobin", "nodes": {"127.0.0.1:1981":20}}, "weight": 2},
{"upstream": {"name": "upstream_B", "type": "roundrobin", "nodes": {"127.0.0.1:1982":10}}, "weight": 2},
{"weight": 1}
]
vars = {
{"arg_name", "==", "jack" }, { "arg_age", "~~", "^[1-9]{1,2}"}
}
},
{
vars = {
{"arg_name2", "in", {"jack", "rose"} }, { "arg_age", "!", "<", 18}
}
}
},
weighted_upstreams = {
{
upstream = {
name = "upstream_A",
type = "roundrobin",
nodes = {
["127.0.0.1:1981"] = 20
}
},
weight = 2
},
{
upstream = {
name = "upstream_B",
type = "roundrobin",
nodes = {
["127.0.0.1:1982"] = 10
}
},
weight = 2
},
{
weight = 1
}
]
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 1
}
} }
}
},
upstream = {
type = "roundrobin",
nodes = {
["127.0.0.1:1980"] = 1
}
}]=]
}
}

local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
json.encode(data)
)
if code >= 300 then
ngx.status = code
Expand Down Expand Up @@ -479,34 +508,60 @@ GET /t
--- config
location /t {
content_by_lua_block {
local json = require("toolkit.json")
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[=[{
"uri": "/server_port",
"plugins": {
"traffic-split": {
"rules": [
local data = {
uri = "/server_port",
plugins = {
["traffic-split"] = {
rules = { {
match = {
{
vars = {
{"arg_name", "==", "jack" }, { "arg_age", "~~", "^[1-9]{1,2}"}
}
},
{
"match": [
{"vars": [["arg_name", "==", "jack"], ["arg_age", "~~", "^[1-9]{1,2}"]]},
{"vars": [["arg_name2", "in", ["jack", "rose"]], ["arg_age2", "!", "<", 18]]}
],
"weighted_upstreams": [
{"upstream": {"name": "upstream_A", "type": "roundrobin", "nodes": {"127.0.0.1:1981":20}}, "weight": 2},
{"upstream": {"name": "upstream_B", "type": "roundrobin", "nodes": {"127.0.0.1:1982":10}}, "weight": 2}
]
vars = {
{"arg_name2", "in", {"jack", "rose"} }, { "arg_age", "!", "<", 18}
}
}
},
weighted_upstreams = {
{
upstream = {
name = "upstream_A",
type = "roundrobin",
nodes = {
["127.0.0.1:1981"] = 20
}
},
weight = 2
},
{
upstream = {
name = "upstream_B",
type = "roundrobin",
nodes = {
["127.0.0.1:1982"] = 10
}
},
weight = 2
}
]
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 1
}
} }
}
},
upstream = {
type = "roundrobin",
nodes = {
["127.0.0.1:1980"] = 1
}
}]=]
}
}
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
json.encode(data)
)
if code >= 300 then
ngx.status = code
Expand Down Expand Up @@ -550,28 +605,52 @@ GET /t
--- config
location /t {
content_by_lua_block {
local json = require("toolkit.json")
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[=[{
"uri": "/server_port",
"plugins": {
"traffic-split": {
"rules": [
local data = {
uri = "/server_port",
plugins = {
["traffic-split"] = {
rules = { {
match = {
{
vars = {
{"arg_name", "==", "jack" }, { "arg_age", "~~", "^[1-9]{1,2}"}
}
}
},
weighted_upstreams = {
{
"match": [
{
"vars": [["arg_name", "==", "jack"], ["arg_age", "~~", "^[1-9]{1,2}"]]
upstream = {
name = "upstream_A",
type = "roundrobin",
nodes = {
["127.0.0.1:1980"] = 1,
["127.0.0.1:1981"] = 2,
["127.0.0.1:1982"] = 2
},
timeout = {
connect = 15,
send = 15,
read = 15
}
],
"weighted_upstreams": [
{"upstream": {"name": "upstream_A", "type": "roundrobin", "nodes": {"127.0.0.1:1980":1, "127.0.0.1:1981":2, "127.0.0.1:1982":2}, "timeout": {"connect": 15, "send": 15, "read": 15}}, "weight": 1}
]
},
weight = 1
}
]
}
}
} }
}
}]=]
},
upstream = {
type = "roundrobin",
nodes = {
["127.0.0.1:1980"] = 1
}
}
}
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
json.encode(data)
)
if code >= 300 then
ngx.status = code
Expand Down Expand Up @@ -676,40 +755,38 @@ qr/dns resolver domain: apiseven.com to \d+.\d+.\d+.\d+/
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"uri": "/server_port",
"plugins": {
"traffic-split": {
"rules": [
local json = require("toolkit.json")

local data = {
uri = "/server_port",
plugins = {
["traffic-split"] = {
rules = {{
weighted_upstreams = {
{
"weighted_upstreams": [
{
"upstream": {
"name": "upstream_A",
"type": "roundrobin",
"nodes": {
"127.0.0.1:1981":1
}
},
"weight": 2
},
{
"weight": 1
}
]
upstream = {
name = "upstream_A",
type = "roundrobin",
nodes = {["127.0.0.1:1981"] = 1}
},
weight = 2
},
{
weight = 1
}
]
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 1
}
}}
}
}]]
},
upstream = {
type = "roundrobin",
nodes = {["127.0.0.1:1980"] = 1}
}
}

local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
json.encode(data)
)
if code >= 300 then
ngx.status = code
Expand Down
Loading

0 comments on commit 15517fe

Please sign in to comment.