Skip to content

Commit

Permalink
add: remove servers docs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
justRkive committed Nov 7, 2023
1 parent 72c76b0 commit 6cc9bcd
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/resolver/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 6cc9bcd

Please sign in to comment.