summaryrefslogtreecommitdiff
path: root/t/proxyunits.lua
diff options
context:
space:
mode:
Diffstat (limited to 't/proxyunits.lua')
-rw-r--r--t/proxyunits.lua78
1 files changed, 70 insertions, 8 deletions
diff --git a/t/proxyunits.lua b/t/proxyunits.lua
index 30bf31f..2bc2ed6 100644
--- a/t/proxyunits.lua
+++ b/t/proxyunits.lua
@@ -130,12 +130,78 @@ function mcp_config_routes(zones)
elseif r:has_flag("O") then
return "HD Oabc\r\n"
end
- return "FAIL"
+ return "NF\r\n"
+ end
+
+ -- Input flags: N10 k c R10
+ -- Output flags: N100 k R100
+ pfx_mg["flagtoken"] = function(r)
+ -- flag_token on non-existing flags: no effect
+ local Ttoken = r:flag_token("T", "T100")
+ local Otoken = r:flag_token("O", nil)
+ local vtoken = r:flag_token("v", "")
+ if vtoken or Otoken or Ttoken then
+ return "ERROR found non-existing flag."
+ end
+
+ -- flag_token to replace: N10 -> N100
+ local found, Ntoken = r:flag_token("N", "N100")
+ if not found or Ntoken ~= "10" then
+ return "ERROR unexpected N token."
+ end
+
+ -- flag_token with nil 2nd arg: equvalent to fetch
+ r:flag_token("k", nil)
+ if not r:has_flag("k") then
+ return "ERROR unexpected k token."
+ end
+
+ -- flag_token with self 2nd arg: no effect
+ r:flag_token("c", "c")
+ if not r:has_flag("c") then
+ return "ERROR unexpected c token 1."
+ end
+
+ -- flag_token with "" 2nd arg: remove
+ r:flag_token("c", "")
+ if r:has_flag("c") then
+ return "ERROR unexpected c token 2."
+ end
+
+ -- repeated flag_token calls: new value is returned.
+ local _, Rtoken = r:flag_token("R", "R100")
+ if Rtoken ~= '10' then
+ return "ERROR unexpected R token 1."
+ end
+ _, Rtoken = r:flag_token("R", "R100")
+ if Rtoken ~= '100' then
+ return "ERROR unexpected R token 2."
+ end
+
+ return "HD\r\n"
+ end
+
+ pfx_ms["request"] = function(r)
+ local key = r:key()
+ local newReq = mcp.request("ms /request/edit 2\r\n", "ab\r\n")
+ return zones.z1(newReq)
+ end
+
+ pfx_mg["request"] = function(r)
+ local key = r:key()
+ if key == "/request/old" then
+ local newReq = mcp.request("mg /request/new c\r\n")
+ return zones.z1(newReq)
+ else
+ local res = zones.z1(r)
+ local newReq = mcp.request("ms /request/a " .. res:vlen() .. "\r\n", res)
+ return zones.z1(newReq)
+ end
end
pfx_get["hasflag"] = function(r)
if r:has_flag("F") then
- return "FAIL"
+ return "ERROR flag found\r\n"
end
return "END\r\n"
end
@@ -150,13 +216,9 @@ function mcp_config_routes(zones)
return zones.z1(r)
else
local token = r:token(2)
- if token == "/token/fetch" then
- return "HD\r\n"
- else
- return "NF\r\n"
- end
+ r:flag_token("P", "P" .. token)
+ return zones.z1(r)
end
- return "FAIL"
end
-- Basic test for routing requests to specific pools.