Skip to content

Commit

Permalink
[Feature] Selectors: Add specific_urls extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Aug 19, 2019
1 parent d0e5bf6 commit ed52028
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lualib/lua_selectors/extractors.lua
Expand Up @@ -278,6 +278,23 @@ e.g. `by_hostname`]],
If no arguments specified, returns list of url objects. Otherwise, calls a specific method,
e.g. `get_tld`]],
},
-- Get specific urls
['specific_urls'] = {
['get_value'] = function(task, args)
local params = args[1] or {}
params.task = task
local urls = lua_util.extract_specific_urls(params)
return urls,'userdata_list'
end,
['description'] = [[Get most specific urls. Arguments are equal to the Lua API function]],
['args_schema'] = {ts.shape{
limit = ts.number + ts.string / tonumber,
esld_limit = (ts.number + ts.string / tonumber):is_optional(),
prefix = ts.string:is_optional(),
need_emails = (ts.boolean + ts.string / lua_util.toboolean):is_optional(),
ignore_redirected = (ts.boolean + ts.string / lua_util.toboolean):is_optional(),
}}
},
-- Get all emails
['emails'] = {
['get_value'] = function(task, args)
Expand Down
12 changes: 12 additions & 0 deletions test/lua/unit/selectors.lua
Expand Up @@ -151,6 +151,18 @@ context("Selectors test", function()
selector = "emails",
expect = {{"mailto://test@example.net"}}},

["specific_urls"] = {
selector = "specific_urls({limit = 1})",
expect = {{"http://example.net"}}},

["specific_urls + emails"] = {
selector = "specific_urls({need_emails = true, limit = 2})",
expect = {{"http://example.net", "mailto://test@example.net"}}},

["specific_urls + emails limit"] = {
selector = "specific_urls({need_emails = true, limit = 1})",
expect = {{"http://example.net"}}},

["pool_var str, default type"] = {
selector = [[pool_var("str_var")]],
expect = {"str 1"}},
Expand Down

0 comments on commit ed52028

Please sign in to comment.