]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
module tests (daf + prefill): switch to shared check_answer()
authorVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 1 Jul 2020 16:27:23 +0000 (18:27 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Wed, 8 Jul 2020 06:42:08 +0000 (08:42 +0200)
I think this eliminates the remaining copies.  Most of the places don't
need all the features, but it still seems worth to deduplicate.

modules/daf/daf.test.lua
modules/prefill/prefill.test/prefill.test.lua

index bd1d9cfe38daea4f09f08d6fa0ab39829ce41467..c0aceecac22a46c7234657d5a069b56f2e6c5544 100644 (file)
@@ -17,18 +17,7 @@ hints['del.'] = '127.0.0.1'
 hints['del2.'] = '127.0.0.1'
 hints['toggle.'] = '127.0.0.1'
 
-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
 
 local function test_sanity()
        check_answer('daf sanity (no rules)', 'pass.', kres.type.A, kres.rcode.NOERROR)
index 2b232edf328468500f89a9d6c1a3ed3c1862d776..64c41ca8808c240bd1b8ca53df6c1f9b16f2f879 100644 (file)
@@ -36,25 +36,13 @@ ev = event.after(0, function () return 1 end)
 trust_anchors.remove('.')
 trust_anchors.add('.                   IN DS 18213 7 2 A1D391053583A4BC597DB9588B296060FC55EAC80B3831CA371BA1FA AE997244')
 
-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] .. ' got ' .. kres.tostring.rcode[pkt: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
-
 -- do not attempt to contact outside world, operate only on cache
 net.ipv4 = false
 net.ipv6 = false
 -- do not listen, test is driven by config code
 env.KRESD_NO_LISTEN = true
 
+local check_answer = require('test_utils').check_answer
 
 local function import_valid_root_zone()
        cache.clear()