From 7a21c8bd6eceeacd58bf41ecc8485c7fe7c9af7e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Wed, 1 Jul 2020 18:27:23 +0200 Subject: [PATCH] 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. --- modules/daf/daf.test.lua | 13 +------------ modules/prefill/prefill.test/prefill.test.lua | 14 +------------- 2 files changed, 2 insertions(+), 25 deletions(-) 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() -- 2.47.2