From 7b59f2ada4711c76b82eb35405416b00bd2ee374 Mon Sep 17 00:00:00 2001 From: James Coglan Date: Wed, 29 May 2024 16:45:01 +0100 Subject: [PATCH] resolved: tests for dns_resource_key_{to,from}_json() 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/resolve/test-dns-rr.c b/src/resolve/test-dns-rr.c index ffb76efecc..a78cb638a3 100644 --- a/src/resolve/test-dns-rr.c +++ b/src/resolve/test-dns-rr.c @@ -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, ©)); + 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() * ================================================================ */ -- 2.25.1