Commit 60cd9361 authored by Thomas Haller's avatar Thomas Haller
Browse files

dns/tests: add test for writing resolv.conf

parent 1c338861
......@@ -613,6 +613,14 @@ create_resolv_conf (const char *const*searches,
return g_string_free (str, FALSE);
}
char *
nmtst_dns_create_resolv_conf (const char *const*searches,
const char *const*nameservers,
const char *const*options)
{
return create_resolv_conf (searches, nameservers, options);
}
static gboolean
write_resolv_conf_contents (FILE *f,
const char *content,
......
......@@ -129,4 +129,10 @@ typedef enum {
void nm_dns_manager_stop (NMDnsManager *self);
/*****************************************************************************/
char *nmtst_dns_create_resolv_conf (const char *const*searches,
const char *const*nameservers,
const char *const*options);
#endif /* __NETWORKMANAGER_DNS_MANAGER_H__ */
......@@ -29,6 +29,8 @@
#include "NetworkManagerUtils.h"
#include "nm-core-internal.h"
#include "dns/nm-dns-manager.h"
#include "nm-test-utils-core.h"
/* Reference implementation for nm_utils_ip6_address_clear_host_address.
......@@ -1864,6 +1866,50 @@ test_utils_file_is_in_path (void)
/*****************************************************************************/
#define _TEST_RC(searches, nameservers, options, expected) \
G_STMT_START { \
const char *const*const _searches = (searches); \
const char *const*const _nameservers = (nameservers); \
const char *const*const _options = (options); \
gs_free char *_content = NULL; \
\
_content = nmtst_dns_create_resolv_conf (_searches, _nameservers, _options); \
g_assert_cmpstr (_content, ==, expected); \
} G_STMT_END
static void
test_dns_create_resolv_conf (void)
{
_TEST_RC (NM_MAKE_STRV ("a"),
NULL,
NULL,
"# Generated by NetworkManager\n"
"search a\n"
"");
_TEST_RC (NM_MAKE_STRV ("a", "b.com"),
NM_MAKE_STRV ("192.168.55.1", "192.168.56.1"),
NM_MAKE_STRV ("opt1", "opt2"),
"# Generated by NetworkManager\n"
"search a b.com\n"
"nameserver 192.168.55.1\n"
"nameserver 192.168.56.1\n"
"options opt1 opt2\n"
"");
_TEST_RC (NM_MAKE_STRV ("a2x456789.b2x456789.c2x456789.d2x456789.e2x456789.f2x456789.g2x456789.h2x456789.i2x456789.j2x4567890",
"a2y456789.b2y456789.c2y456789.d2y456789.e2y456789.f2y456789.g2y456789.h2y456789.i2y456789.j2y4567890",
"a2z456789.b2z456789.c2z456789.d2z456789.e2z456789.f2z456789.g2z456789.h2z456789.i2z456789.j2z4567890"),
NULL,
NULL,
"# Generated by NetworkManager\n"
"search a2x456789.b2x456789.c2x456789.d2x456789.e2x456789.f2x456789.g2x456789.h2x456789.i2x456789.j2x4567890 a2y456789.b2y456789.c2y456789.d2y456789.e2y456789.f2y456789.g2y456789.h2y456789.i2y456789.j2y4567890 a2z456789.b2z456789.c2z456789.d2z456789.e2z456789.f2z456789.g2z456789.h2z456789.i2z456789.j2z4567890\n"
"");
}
/*****************************************************************************/
NMTST_DEFINE ();
int
......@@ -1912,6 +1958,8 @@ main (int argc, char **argv)
g_test_add_func ("/general/test_utils_file_is_in_path", test_utils_file_is_in_path);
g_test_add_func ("/general/test_dns_create_resolv_conf", test_dns_create_resolv_conf);
return g_test_run ();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment