From: Vladimír Čunát Date: Wed, 1 Jul 2020 16:27:23 +0000 (+0200) Subject: module tests (daf + prefill): switch to shared check_answer() X-Git-Tag: v5.1.3~29^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a21c8bd6eceeacd58bf41ecc8485c7fe7c9af7e;p=thirdparty%2Fknot-resolver.git module tests (daf + prefill): switch to shared check_answer() I think this eliminates the remaining copies. Most of the places don't need all the features, but it still seems worth to deduplicate. --- diff --git a/modules/daf/daf.test.lua b/modules/daf/daf.test.lua index bd1d9cfe3..c0aceecac 100644 --- a/modules/daf/daf.test.lua +++ b/modules/daf/daf.test.lua @@ -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) diff --git a/modules/prefill/prefill.test/prefill.test.lua b/modules/prefill/prefill.test/prefill.test.lua index 2b232edf3..64c41ca88 100644 --- a/modules/prefill/prefill.test/prefill.test.lua +++ b/modules/prefill/prefill.test/prefill.test.lua @@ -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()