mirror of
https://github.com/isc-projects/bind9.git
synced 2026-04-28 01:28:05 -04:00
Modify rrsets_equal() to optionally compare TTL
(cherry picked from commit 5af3b713af)
This commit is contained in:
parent
4f03ec88b8
commit
ff6fc0c98f
1 changed files with 28 additions and 4 deletions
|
|
@ -9,11 +9,12 @@
|
|||
# See the COPYRIGHT file distributed with this work for additional
|
||||
# information regarding copyright ownership.
|
||||
|
||||
from typing import Any
|
||||
from typing import Any, Optional
|
||||
|
||||
import dns.rcode
|
||||
import dns.message
|
||||
|
||||
import isctest.log
|
||||
|
||||
# compatiblity with dnspython<2.0.0
|
||||
try:
|
||||
|
|
@ -38,8 +39,31 @@ def servfail(message: dns.message.Message) -> None:
|
|||
rcode(message, dns_rcode.SERVFAIL)
|
||||
|
||||
|
||||
def rrsets_equal(first_rrset: dns.rrset.RRset, second_rrset: dns.rrset.RRset) -> None:
|
||||
def rrsets_equal(
|
||||
first_rrset: dns.rrset.RRset,
|
||||
second_rrset: dns.rrset.RRset,
|
||||
compare_ttl: Optional[bool] = False,
|
||||
) -> None:
|
||||
"""Compare two RRset (optionally including TTL)"""
|
||||
|
||||
def compare_rrs(rr1, rrset):
|
||||
rr2 = next((other_rr for other_rr in rrset if rr1 == other_rr), None)
|
||||
assert rr2 is not None, f"No corresponding RR found for: {rr1}"
|
||||
if compare_ttl:
|
||||
assert rr1.ttl == rr2.ttl
|
||||
|
||||
isctest.log.debug(
|
||||
"%s() first RRset:\n%s",
|
||||
rrsets_equal.__name__,
|
||||
"\n".join([str(rr) for rr in first_rrset]),
|
||||
)
|
||||
isctest.log.debug(
|
||||
"%s() second RRset:\n%s",
|
||||
rrsets_equal.__name__,
|
||||
"\n".join([str(rr) for rr in second_rrset]),
|
||||
)
|
||||
for rr in first_rrset:
|
||||
assert rr in second_rrset
|
||||
compare_rrs(rr, second_rrset)
|
||||
for rr in second_rrset:
|
||||
assert rr in first_rrset
|
||||
compare_rrs(rr, first_rrset)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue