mirror of
https://github.com/graygnuorg/pound.git
synced 2026-10-25 10:19:36 +03:00
118 lines
1.8 KiB
Plaintext
118 lines
1.8 KiB
Plaintext
# This file is part of pound testsuite. -*- autotest -*-
|
|
# Copyright (C) 2025-2026 Sergey Poznyakoff
|
|
#
|
|
# Pound is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Pound is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with pound. If not, see <http://www.gnu.org/licenses/>.
|
|
AT_SETUP([LuaMatch])
|
|
AT_KEYWORDS([cond lua lua-match])
|
|
|
|
AT_SKIP_IF([test "$LUA_AVAILABLE" != 1])
|
|
|
|
AT_DATA([xtest.lua],
|
|
[function xtest(a)
|
|
pound.log(pound.DEBUG, "xtest called with argument " .. a)
|
|
return tonumber(a) > 10
|
|
end
|
|
])
|
|
|
|
PT_CHECK([Lua
|
|
Load "xtest.lua"
|
|
End
|
|
ListenHTTP
|
|
Service
|
|
Header ["X-Test" -re "([0-9]+)$"]
|
|
LuaMatch "xtest" "$1"
|
|
Backend
|
|
End
|
|
End
|
|
End
|
|
],
|
|
[GET /echo/foo
|
|
X-Test: 2
|
|
end
|
|
|
|
503
|
|
end
|
|
|
|
GET /echo/foo
|
|
X-Test: 22
|
|
end
|
|
|
|
200
|
|
end
|
|
])
|
|
|
|
AT_DATA([xtestmod.lua],
|
|
[local matcher = {}
|
|
function matcher.xtest(a)
|
|
pound.log(pound.DEBUG, "xtest called with argument " .. a)
|
|
return tonumber(a) > 10
|
|
end
|
|
return matcher
|
|
])
|
|
|
|
PT_CHECK([Lua
|
|
Load "xtestmod.lua"
|
|
End
|
|
ListenHTTP
|
|
Service
|
|
Header ["X-Test" -re "([0-9]+)$"]
|
|
LuaMatch "xtestmod.xtest" "$1"
|
|
Backend
|
|
End
|
|
End
|
|
End
|
|
],
|
|
[GET /echo/foo
|
|
X-Test: 2
|
|
end
|
|
|
|
503
|
|
end
|
|
|
|
GET /echo/foo
|
|
X-Test: 22
|
|
end
|
|
|
|
200
|
|
end
|
|
])
|
|
|
|
PT_CHECK([Lua
|
|
Load "xtestmod.lua" "m10"
|
|
End
|
|
ListenHTTP
|
|
Service
|
|
Header ["X-Test" -re "([0-9]+)$"]
|
|
LuaMatch "m10.xtest" "$1"
|
|
Backend
|
|
End
|
|
End
|
|
End
|
|
],
|
|
[GET /echo/foo
|
|
X-Test: 2
|
|
end
|
|
|
|
503
|
|
end
|
|
|
|
GET /echo/foo
|
|
X-Test: 22
|
|
end
|
|
|
|
200
|
|
end
|
|
])
|
|
AT_CLEANUP
|