dns/tests: add test for writing resolv.conf

(cherry picked from commit 60cd93612f)
This commit is contained in:
Thomas Haller 2018-11-12 10:44:19 +01:00
parent 4515d36fa1
commit b78a0ebcb1
3 changed files with 62 additions and 0 deletions

View file

@ -626,6 +626,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,

View file

@ -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__ */

View file

@ -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.
@ -1845,6 +1847,50 @@ test_nm_utils_exp10 (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
@ -1891,6 +1937,8 @@ main (int argc, char **argv)
g_test_add_func ("/general/stable-id/parse", test_stable_id_parse);
g_test_add_func ("/general/stable-id/generated-complete", test_stable_id_generated_complete);
g_test_add_func ("/general/test_dns_create_resolv_conf", test_dns_create_resolv_conf);
return g_test_run ();
}