2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-29 13:38:26 +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)
def section_equal(sec1: list, sec2: list) -> None:
# convert an RRset to a normalized string (lower case, TTL=0)
# so it can be used as a set member.
def normalized(rrset):
ttl = rrset.ttl
rrset.ttl = 0
s = str(rrset).lower()
rrset.ttl = ttl
return s
# 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 section_equal(first_section: list, second_section: list) -> None:
for rrset in first_section:
assert (
rrset in second_section
), f"No corresponding RRset found in second section: {rrset}"
for rrset in second_section:
assert (
rrset in first_section
), f"No corresponding RRset found in first section: {rrset}"
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.authority, res2.authority)
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):
assert res1.question == res2.question
section_equal(res1.question, res2.question)
section_equal(res1.answer, res2.answer)
assert res1.rcode() == res2.rcode()