From 6cc9bcd5dabd8315c1765167d55f59576cf4509b Mon Sep 17 00:00:00 2001 From: Katia Fredes Date: Tue, 7 Nov 2023 16:04:37 -0300 Subject: [PATCH] add: remove servers docs and tests --- src/resolver/config.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/resolver/config.rs b/src/resolver/config.rs index a639123f..34340346 100644 --- a/src/resolver/config.rs +++ b/src/resolver/config.rs @@ -121,8 +121,24 @@ impl ResolverConfig { self.name_servers.push((conn_udp,conn_tcp)); } - // TODO: remove all servers?? - pub fn remove_server(&mut self) { + /// Remove all servers from the list of Name Servers. + /// + /// # Examples + /// + /// ``` + /// use std::net::IpAddr; + /// use std::time::Duration; + /// use dns_resolver::client::client_connection::ConnectionProtocol; + /// use dns_resolver::resolver::config::ResolverConfig; + /// + /// let mut resolver_config = ResolverConfig::default(); + /// let addr = IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)); + /// resolver_config.add_servers(addr); + /// assert_eq!(resolver_config.get_name_servers().len(), 2); + /// resolver_config.remove_servers(); + /// assert_eq!(resolver_config.get_name_servers().len(), 0); + /// ``` + pub fn remove_servers(&mut self) { self.name_servers = Vec::new(); } } @@ -345,4 +361,14 @@ mod tests_resolver_config { assert_eq!(resolver_config.get_cache_enabled(), false); } + + #[test] + fn remove_servers() { + let mut resolver_config = ResolverConfig::default(); + let addr = IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)); + resolver_config.add_servers(addr); + assert_eq!(resolver_config.get_name_servers().len(), 2); + resolver_config.remove_servers(); + assert_eq!(resolver_config.get_name_servers().len(), 0); + } }