in kong/spec/01-unit/21-dns-client/02-client_spec.lua [101:195]
function() client.init({order = {"LAST", "a", "aa"}}) end,
"Invalid dns record type in order array; aa"
)
end)
it("succeeds with order unset", function()
assert.is.True(client.init({order = nil}))
end)
it("succeeds without i/o access", function()
local result, err = assert(client.init({
nameservers = { "8.8.8.8:53" },
hosts = {},
resolvConf = {},
}))
assert.is.True(result)
assert.is.Nil(err)
assert.are.equal(#client.getcache(), 0)
end)
describe("inject localhost:", function()
it("if absent", function()
local result, err, record
result, err = assert(client.init({
nameservers = { "8.8.8.8:53" },
resolvConf = {},
hosts = {},
}))
assert.is.True(result)
assert.is.Nil(err)
record = client.getcache():get("28:localhost")
assert.equal("[::1]", record[1].address)
record = client.getcache():get("1:localhost")
assert.equal("127.0.0.1", record[1].address)
end)
it("not if ipv4 exists", function()
local result, err, record
result, err = assert(client.init({
nameservers = { "8.8.8.8:53" },
resolvConf = {},
hosts = {"1.2.3.4 localhost"},
}))
assert.is.True(result)
assert.is.Nil(err)
record = client.getcache():get("28:localhost")
assert.is_nil(record)
record = client.getcache():get("1:localhost")
assert.equal("1.2.3.4", record[1].address)
end)
it("not if ipv6 exists", function()
local result, err, record
result, err = assert(client.init({
nameservers = { "8.8.8.8:53" },
resolvConf = {},
hosts = {"::1:2:3:4 localhost"},
}))
assert.is.True(result)
assert.is.Nil(err)
record = client.getcache():get("28:localhost")
assert.equal("[::1:2:3:4]", record[1].address)
record = client.getcache():get("1:localhost")
assert.is_nil(record)
end)
end)
end)
describe("iterating searches", function()
describe("without type", function()
it("works with a 'search' option", function()
assert(client.init({
resolvConf = {
"nameserver 8.8.8.8",
"search one.com two.com",
"options ndots:1",
}
}))
local list = {}
for qname, qtype in client._search_iter("host", nil) do
table.insert(list, tostring(qname)..":"..tostring(qtype))
end