resolved: tests for dns_resource_key_{to,from}_json()
authorJames Coglan <james@neighbourhood.ie>
Wed, 29 May 2024 15:45:01 +0000 (16:45 +0100)
committerLuca Boccassi <bluca@debian.org>
Tue, 23 Jul 2024 11:44:35 +0000 (12:44 +0100)
This test doesn't check the generated JSON data in detail, it simply
tests that round-tripping an RR key through the JSON representation
preserves its data.

src/resolve/test-dns-rr.c

index ffb76efeccaf2258703c2e60fa666c17c57b59b3..a78cb638a3b659f7c62149322d1790dd17247f83 100644 (file)
@@ -697,6 +697,26 @@ TEST(dns_resource_key_to_string) {
         ASSERT_STREQ(ans, "www.example.com IN CNAME");
 }
 
+/* ================================================================
+ * dns_resource_key_{to,from}_json()
+ * ================================================================ */
+
+TEST(dns_resource_key_from_json) {
+        _cleanup_(dns_resource_key_unrefp) DnsResourceKey *key = NULL, *copy = NULL;
+        _cleanup_(sd_json_variant_unrefp) sd_json_variant *json = NULL;
+
+        key = dns_resource_key_new(DNS_CLASS_IN, DNS_TYPE_A, "www.example.com");
+        ASSERT_NOT_NULL(key);
+
+        ASSERT_OK(dns_resource_key_to_json(key, &json));
+        ASSERT_NOT_NULL(json);
+
+        ASSERT_OK(dns_resource_key_from_json(json, &copy));
+        ASSERT_EQ(copy->class, DNS_CLASS_IN);
+        ASSERT_EQ(copy->type, DNS_TYPE_A);
+        ASSERT_STREQ(dns_resource_key_name(copy), "www.example.com");
+}
+
 /* ================================================================
  * dns_resource_key_reduce()
  * ================================================================ */