Skip to content

Commit

Permalink
Merge together lookup() and lookup_with_hosts()
Browse files Browse the repository at this point in the history
  • Loading branch information
hch12907 committed Mar 12, 2024
1 parent 7e36249 commit 652e1f4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion crates/resolver/src/async_resolver.rs
Expand Up @@ -367,7 +367,7 @@ impl<P: ConnectionProvider> AsyncResolver<P> {
L: From<Lookup> + Send + 'static,
{
let names = self.build_names(name);
LookupFuture::lookup_with_hosts(
LookupFuture::lookup(
names,
record_type,
options,
Expand Down
24 changes: 6 additions & 18 deletions crates/resolver/src/lookup.rs
Expand Up @@ -272,23 +272,6 @@ impl<C> LookupFuture<C>
where
C: DnsHandle + 'static,
{
/// Perform a lookup from a name and type to a set of RDatas
///
/// # Arguments
///
/// * `names` - a set of DNS names to attempt to resolve, they will be attempted in queue order, i.e. the first is `names.pop()`. Upon each failure, the next will be attempted.
/// * `record_type` - type of record being sought
/// * `client_cache` - cache with a connection to use for performing all lookups
#[doc(hidden)]
pub fn lookup(
names: Vec<Name>,
record_type: RecordType,
options: DnsRequestOptions,
client_cache: CachingClient<C>,
) -> Self {
Self::lookup_with_hosts(names, record_type, options, client_cache, None)
}

/// Perform a lookup from a name and type to a set of RDatas, taking the local
/// hosts file into account.
///
Expand All @@ -299,7 +282,7 @@ where
/// * `client_cache` - cache with a connection to use for performing all lookups
/// * `hosts` - the local host file, the records inside it will be prioritized over the upstream DNS server
#[doc(hidden)]
pub fn lookup_with_hosts(
pub fn lookup(
mut names: Vec<Name>,
record_type: RecordType,
options: DnsRequestOptions,
Expand Down Expand Up @@ -663,6 +646,7 @@ pub mod tests {
RecordType::A,
DnsRequestOptions::default(),
CachingClient::new(0, mock(vec![v4_message()]), false),
None,
))
.unwrap()
.iter()
Expand All @@ -681,6 +665,7 @@ pub mod tests {
RecordType::A,
DnsRequestOptions::default(),
CachingClient::new(0, mock(vec![v4_message()]), false),
None,
))
.unwrap()
.records()[0]
Expand All @@ -700,6 +685,7 @@ pub mod tests {
RecordType::A,
DnsRequestOptions::default(),
CachingClient::new(0, mock(vec![v4_message()]), false),
None,
))
.unwrap()
.into_iter()
Expand All @@ -716,6 +702,7 @@ pub mod tests {
RecordType::A,
DnsRequestOptions::default(),
CachingClient::new(0, mock(vec![error()]), false),
None,
))
.is_err());
}
Expand All @@ -731,6 +718,7 @@ pub mod tests {
RecordType::A,
DnsRequestOptions::default(),
CachingClient::new(0, mock(vec![empty()]), false),
None,
))
.expect_err("this should have been a NoRecordsFound")
.proto()
Expand Down
8 changes: 8 additions & 0 deletions tests/integration-tests/tests/lookup_tests.rs
Expand Up @@ -45,6 +45,7 @@ fn test_lookup() {
RecordType::A,
Default::default(),
CachingClient::new(0, client, false),
None,
);
let lookup = io_loop.block_on(lookup).unwrap();

Expand Down Expand Up @@ -188,6 +189,7 @@ fn test_mock_lookup() {
RecordType::A,
Default::default(),
CachingClient::new(0, client, false),
None,
);

let io_loop = Runtime::new().unwrap();
Expand Down Expand Up @@ -219,6 +221,7 @@ fn test_cname_lookup() {
RecordType::A,
Default::default(),
CachingClient::new(0, client, false),
None,
);

let io_loop = Runtime::new().unwrap();
Expand Down Expand Up @@ -255,6 +258,7 @@ fn test_cname_lookup_preserve() {
RecordType::A,
Default::default(),
CachingClient::new(0, client, true),
None,
);

let io_loop = Runtime::new().unwrap();
Expand Down Expand Up @@ -292,6 +296,7 @@ fn test_chained_cname_lookup() {
RecordType::A,
Default::default(),
CachingClient::new(0, client, false),
None,
);

let io_loop = Runtime::new().unwrap();
Expand Down Expand Up @@ -335,6 +340,7 @@ fn test_chained_cname_lookup_preserve() {
RecordType::A,
Default::default(),
CachingClient::new(0, client, true),
None,
);

let io_loop = Runtime::new().unwrap();
Expand Down Expand Up @@ -421,6 +427,7 @@ fn test_max_chained_lookup_depth() {
RecordType::A,
Default::default(),
client.clone(),
None,
);

let io_loop = Runtime::new().unwrap();
Expand All @@ -434,6 +441,7 @@ fn test_max_chained_lookup_depth() {
RecordType::A,
Default::default(),
client,
None,
);

println!("performing followup resolve, should work");
Expand Down

0 comments on commit 652e1f4

Please sign in to comment.