From ff6fc0c98fcaf2f526eb925e1be7f9f4d0f38082 Mon Sep 17 00:00:00 2001 From: Michal Nowak Date: Tue, 19 Mar 2024 10:45:59 +0100 Subject: [PATCH] Modify rrsets_equal() to optionally compare TTL (cherry picked from commit 5af3b713af8ba67e521051352ad5d9cf0459c4fb) --- bin/tests/system/isctest/check.py | 32 +++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/bin/tests/system/isctest/check.py b/bin/tests/system/isctest/check.py index 21c3988dc57..dad327706a6 100644 --- a/bin/tests/system/isctest/check.py +++ b/bin/tests/system/isctest/check.py @@ -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) + -- 2.47.3