From c92a6b85fe5b60dce38338ec3b0568391b5cbe8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicki=20K=C5=99=C3=AD=C5=BEek?= Date: Fri, 25 Jul 2025 11:09:30 +0200 Subject: [PATCH] Unify RR counting in isctest.check helper Use a common function to count the number of RRs in any section of the DNS message. For the ADDITIONAL section, stick with the dnspython convention of not including OPT and TSIG. (cherry picked from commit efd60348b9280383fe5d50042a94ea363390356d) --- bin/tests/system/isctest/check.py | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/bin/tests/system/isctest/check.py b/bin/tests/system/isctest/check.py index fb8aa98cdc..7ba0767d13 100644 --- a/bin/tests/system/isctest/check.py +++ b/bin/tests/system/isctest/check.py @@ -156,28 +156,10 @@ def empty_answer(message: dns.message.Message) -> None: assert not message.answer, str(message) -def answer_count_eq(m: dns.message.Message, expected: int): - count = sum(max(1, len(rrs)) for rrs in m.answer) - assert count == expected, str(m) - - -def authority_count_eq(m: dns.message.Message, expected: int): - count = sum(max(1, len(rrs)) for rrs in m.authority) - assert count == expected, str(m) - - -def additional_count_eq(m: dns.message.Message, expected: int): - count = sum(max(1, len(rrs)) for rrs in m.additional) - - # add one for the OPT? - opt = bool(m.opt) if hasattr(m, "opt") else bool(m.edns >= 0) - count += 1 if opt else 0 - - # add one for the TSIG? - tsig = bool(m.tsig) if hasattr(m, "tsig") else m.had_tsig - count += 1 if tsig else 0 - - assert count == expected, str(m) +def rr_count_eq(section: list, expected: int): + # NOTE: OPT and TSIG records aren't included in the count for ADDITIONAL section + count = sum(len(rrset) for rrset in section) + assert count == expected, str(section) def is_response_to(response: dns.message.Message, query: dns.message.Message) -> None: