From 7c487075bc738b27be77558ad8cc0d588245d9fa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20De=20Keersmaeker?=
 <francois.dekeersmaeker@uclouvain.be>
Date: Sat, 16 Nov 2024 22:22:00 +0100
Subject: [PATCH] Updated unit tests

---
 .gitignore                       |  1 +
 test/sample_dns_cache_update.txt |  8 ++++++++
 test/test_sample_file.py         | 16 ++++++++++++++++
 3 files changed, 25 insertions(+)
 create mode 100644 test/sample_dns_cache_update.txt

diff --git a/.gitignore b/.gitignore
index 419d0b3..b2e89b4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,4 +6,5 @@ dist
 *.egg-info
 .pytest_cache
 *.txt
+*.json
 test.py
diff --git a/test/sample_dns_cache_update.txt b/test/sample_dns_cache_update.txt
new file mode 100644
index 0000000..5ba376c
--- /dev/null
+++ b/test/sample_dns_cache_update.txt
@@ -0,0 +1,8 @@
+; unbound cache dump
+START_RRSET_CACHE
+test.com.   300    IN    A    93.184.216.34
+; CNAME records
+test1.local. 300 IN   A   192.168.1.100
+test.local.  300 IN   CNAME  test1.local.
+END_RRSET_CACHE
+EOF
diff --git a/test/test_sample_file.py b/test/test_sample_file.py
index 5b3d727..c281c78 100644
--- a/test/test_sample_file.py
+++ b/test/test_sample_file.py
@@ -9,6 +9,7 @@ from dns_unbound_cache_reader import DnsTableKeys
 self_path = os.path.abspath(__file__)
 self_dir = os.path.dirname(self_path)
 sample_cache_file = os.path.join(self_dir, "sample_dns_cache.txt")
+sample_cache_file_update = os.path.join(self_dir, "sample_dns_cache_update.txt")
 
 
 ### TEST FUNCTIONS ###
@@ -35,3 +36,18 @@ def test_read_sample_cache_file() -> None:
     assert dns_table_alias["example1.local"] == "example.local"
     assert dns_table_alias["server1.example.com"] == "_tcp_.matter.example.com"
     assert dns_table_alias["server2.example.com"] == "_tcp_.matter.example.com"
+
+
+def test_update_dns_table() -> None:
+    """
+    Test updating an existing DNS table.
+    """
+    dns_table = dns_reader.read_dns_cache(file=sample_cache_file)
+    dns_table = dns_reader.update_dns_table(dns_table, file=sample_cache_file_update)
+
+    dns_table_ip = dns_table[DnsTableKeys.IP.name]
+    assert dns_table_ip["93.184.216.34"] == "test.com"
+    assert dns_table_ip["192.168.1.100"] == "test.local"
+    
+    dns_table_alias = dns_table[DnsTableKeys.ALIAS.name]
+    assert dns_table_alias["test1.local"] == "test.local"
\ No newline at end of file
-- 
GitLab