diff --git a/src/resolve/test-dns-rr.c b/src/resolve/test-dns-rr.c index ffb76efecca..a78cb638a3b 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() * ================================================================ */