]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
tests: move check_answer() into require('tests_utils')
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 25 May 2020 11:53:57 +0000 (13:53 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 25 May 2020 13:32:49 +0000 (15:32 +0200)
daemon/cache.test/clear.test.lua
tests/config/test_utils.lua

index 91e851e587db24bdfb7fe5fb4b0f0c0c3eb37125..37bd8ab27ab59a1f4ac644203a1c7cf13651c4cc 100644 (file)
@@ -37,18 +37,7 @@ ev = event.after(0, function () return 1 end)
 trust_anchors.remove('.')
 trust_anchors.add('. IN DS 48409 8 2 3D63A0C25BCE86621DE63636F11B35B908EFE8E9381E0E3E9DEFD89EA952C27D')
 
-local function check_answer(desc, qname, qtype, expected_rcode)
-       qtype_str = kres.tostring.type[qtype]
-       callback = function(pkt)
-               same(pkt:rcode(), expected_rcode,
-                    desc .. ': expecting answer for query ' .. qname .. ' ' .. qtype_str
-                     .. ' with rcode ' .. kres.tostring.rcode[expected_rcode])
-
-               ok((pkt:ancount() > 0) == (pkt:rcode() == kres.rcode.NOERROR),
-                  desc ..': checking number of answers for ' .. qname .. ' ' .. qtype_str)
-       end
-       resolve(qname, qtype, kres.class.IN, {}, callback)
-end
+local check_answer = require('test_utils').check_answer
 
 -- do not attempt to contact outside world, operate only on cache
 net.ipv4 = false
index 3771205bc8dcaa1bfe8881ecf7ec119f7b220c60..24737e7ce9ad5e417be849b300dbfedca65cea7f 100644 (file)
@@ -39,4 +39,17 @@ function M.not_contains(table, value, message)
        return contains(fail, pass, table, value, message)
 end
 
+function M.check_answer(desc, qname, qtype, expected_rcode)
+       qtype_str = kres.tostring.type[qtype]
+       callback = function(pkt)
+               same(pkt:rcode(), expected_rcode,
+                    desc .. ': expecting answer for query ' .. qname .. ' ' .. qtype_str
+                     .. ' with rcode ' .. kres.tostring.rcode[expected_rcode])
+
+               ok((pkt:ancount() > 0) == (pkt:rcode() == kres.rcode.NOERROR),
+                  desc ..': checking number of answers for ' .. qname .. ' ' .. qtype_str)
+       end
+       resolve(qname, qtype, kres.class.IN, {}, callback)
+end
+
 return M