From 491777e9e965a0a7f6c31f40c0f04ac196c7cf46 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Mon, 25 May 2020 15:20:45 +0200 Subject: [PATCH] tests check_answer(): support testing NODATA The fact that it's not a real separate RCODE is always complicating stuff. Also avoid using non-local variables. --- tests/config/test_utils.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/config/test_utils.lua b/tests/config/test_utils.lua index 5b3918887..8d159c9ca 100644 --- a/tests/config/test_utils.lua +++ b/tests/config/test_utils.lua @@ -39,16 +39,20 @@ function M.not_contains(table, value, message) return contains(fail, pass, table, value, message) end +M.NODATA = -1 -- Resolve a name and check the answer. Do *not* return until finished. function M.check_answer(desc, qname, qtype, expected_rcode) - qtype_str = kres.tostring.type[qtype] + local qtype_str = kres.tostring.type[qtype] + local wire_rcode = expected_rcode + if expected_rcode == M.NODATA then wire_rcode = kres.rcode.NOERROR end + local done = false - callback = function(pkt) - same(pkt:rcode(), expected_rcode, + local callback = function(pkt) + same(pkt:rcode(), wire_rcode, desc .. ': expecting answer for query ' .. qname .. ' ' .. qtype_str - .. ' with rcode ' .. kres.tostring.rcode[expected_rcode]) + .. ' with rcode ' .. kres.tostring.rcode[wire_rcode]) - ok((pkt:ancount() > 0) == (pkt:rcode() == kres.rcode.NOERROR), + ok((pkt:ancount() > 0) == (expected_rcode == kres.rcode.NOERROR), desc ..': checking number of answers for ' .. qname .. ' ' .. qtype_str) done = true end -- 2.47.2