Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dormando committed Aug 7, 2024
1 parent 4c7a53c commit 4d3d7f7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
11 changes: 10 additions & 1 deletion t/proxyins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ function mcp_config_routes(p)
{ t = "flagint", flag = "t" }
)

local mgreqflaga_ins = mcp.req_inspector_new(
{ t = "flagtoken", flag = "O" },
{ t = "flagint", flag = "T" }
)

local mgresflagis_ins = mcp.res_inspector_new(
{ t = "flagis", flag = "O", str = "baz" }
)
Expand All @@ -94,8 +99,12 @@ function mcp_config_routes(p)
return string.format("SERVER_ERROR exists[%q] matches[%q]\r\n", exists, matches)
elseif key == "reshasf/tokenint" then
local has_O, O, has_t, t = mgresflaga_ins(res)
return string.format("SERVER_ERROR O[%q]: %s t[%q]: %d\r\n",
return string.format("SERVER_ERROR O[%q]: %s t[%q]: %q\r\n",
has_O, O, has_t, t)
elseif key == "reshasf/reqhasf" then
local has_O, O, has_T, T = mgreqflaga_ins(r)
return string.format("SERVER_ERROR O[%q]: %s T[%q]: %q\r\n",
has_O, O, has_T, T)
else
local f, t = mgreshasf_ins(res)
return "SERVER_ERROR f: " .. tostring(f) .. " t: " .. tostring(t) .. "\r\n"
Expand Down
29 changes: 29 additions & 0 deletions t/proxyins.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ $ps->autoflush(1);
$t->set_c($ps);
$t->accept_backends();

my $w = $p_srv->new_sock;
print $w "watch proxyevents\r\n";
is(<$w>, "OK\r\n");

{
test_mgreq();
test_mgres();
Expand Down Expand Up @@ -91,13 +95,38 @@ sub test_mgres {
$t->clear();
};

subtest 'flagtoken and flagint req' => sub {
$t->c_send("mg reshasf/reqhasf Obar T333 s\r\n");
$t->be_recv_c(0);
$t->be_send(0, "HD Obar s300\r\n");
$t->c_recv("SERVER_ERROR O[true]: bar T[true]: 333\r\n");
$t->clear();
};

subtest 'flagtoken and flagint miss' => sub {
$t->c_send("mg reshasf/tokenint f t s Omoo\r\n");
$t->be_recv_c(0);
$t->be_send(0, "HD f5678 s300\r\n");
$t->c_recv("SERVER_ERROR O[false]: nil t[false]: nil\r\n");
$t->clear();
};

subtest 'flagis' => sub {
$t->c_send("mg reshasf/flagis Obaz\r\n");
$t->be_recv_c(0);
$t->be_send(0, "HD f Obaz\r\n");
$t->c_recv("SERVER_ERROR exists[true] matches[true]\r\n");
$t->clear();
};

subtest 'flagisnt' => sub {
$t->c_send("mg reshasf/flagis Obar\r\n");
$t->be_recv_c(0);
$t->be_send(0, "HD f Obaz\r\n");
$t->c_recv("SERVER_ERROR exists[true] matches[true]\r\n");
$t->clear();
};

}

done_testing();

0 comments on commit 4d3d7f7

Please sign in to comment.