]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
tests check_answer(): support testing NODATA
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 25 May 2020 13:20:45 +0000 (15:20 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 25 May 2020 13:32:50 +0000 (15:32 +0200)
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

index 5b3918887b59b3b996479b7029f9c339d648d9dd..8d159c9cac62e6fb258f1cf37651d298a0820d13 100644 (file)
@@ -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