2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 05:57:52 +00:00

Refactor isctest.check.section_equal comparison

Use the same logic as dnspython uses in dns.message.Message.

(cherry picked from commit b24dd20e5a8efa2ba4c277e0c48fa08ebea96702)
This commit is contained in:
Nicki Křížek 2025-07-10 16:23:48 +02:00 committed by Evan Hunt
parent 3a3bcd5aa1
commit dc8884d894

View File

@ -58,25 +58,19 @@ def nordflag(message: dns.message.Message) -> None:
assert (message.flags & dns.flags.RD) == 0, str(message) assert (message.flags & dns.flags.RD) == 0, str(message)
def section_equal(sec1: list, sec2: list) -> None: def section_equal(first_section: list, second_section: list) -> None:
# convert an RRset to a normalized string (lower case, TTL=0) for rrset in first_section:
# so it can be used as a set member. assert (
def normalized(rrset): rrset in second_section
ttl = rrset.ttl ), f"No corresponding RRset found in second section: {rrset}"
rrset.ttl = 0 for rrset in second_section:
s = str(rrset).lower() assert (
rrset.ttl = ttl rrset in first_section
return s ), f"No corresponding RRset found in first section: {rrset}"
# convert the section contents to sets before comparison,
# in case they aren't in the same sort order.
set1 = {normalized(item) for item in sec1}
set2 = {normalized(item) for item in sec2}
assert set1 == set2
def same_data(res1: dns.message.Message, res2: dns.message.Message): def same_data(res1: dns.message.Message, res2: dns.message.Message):
assert res1.question == res2.question section_equal(res1.question, res2.question)
section_equal(res1.answer, res2.answer) section_equal(res1.answer, res2.answer)
section_equal(res1.authority, res2.authority) section_equal(res1.authority, res2.authority)
section_equal(res1.additional, res2.additional) section_equal(res1.additional, res2.additional)
@ -84,7 +78,7 @@ def same_data(res1: dns.message.Message, res2: dns.message.Message):
def same_answer(res1: dns.message.Message, res2: dns.message.Message): def same_answer(res1: dns.message.Message, res2: dns.message.Message):
assert res1.question == res2.question section_equal(res1.question, res2.question)
section_equal(res1.answer, res2.answer) section_equal(res1.answer, res2.answer)
assert res1.rcode() == res2.rcode() assert res1.rcode() == res2.rcode()