mirror of
https://github.com/bytedance/g3.git
synced 2026-05-05 07:10:51 +00:00
initial commit
This commit is contained in:
commit
13716f4923
1425 changed files with 163227 additions and 0 deletions
46
lib/g3-resolver/tests/simple.rs
Normal file
46
lib/g3-resolver/tests/simple.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright 2023 ByteDance and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use std::net::SocketAddr;
|
||||
use std::str::FromStr;
|
||||
|
||||
use tokio::runtime::Builder;
|
||||
|
||||
use g3_resolver::{
|
||||
driver::c_ares::CAresDriverConfig, AnyResolveDriverConfig, ResolverBuilder, ResolverConfig,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn simple_query() {
|
||||
let rt = Builder::new_current_thread().enable_all().build().unwrap();
|
||||
rt.block_on(async {
|
||||
let mut cares_config = CAresDriverConfig::default();
|
||||
cares_config.add_server(SocketAddr::from_str("223.5.5.5:53").unwrap());
|
||||
let config = ResolverConfig {
|
||||
name: String::new(),
|
||||
driver: AnyResolveDriverConfig::CAres(cares_config),
|
||||
runtime: Default::default(),
|
||||
};
|
||||
let resolver = ResolverBuilder::new(config).build().unwrap();
|
||||
let handle = resolver.get_handle();
|
||||
let mut job = handle.get_v4("www.xjtu.edu.cn".to_string()).unwrap();
|
||||
let data = job.recv().await;
|
||||
assert!(data.is_ok());
|
||||
let mut job = handle.get_v4("www.xjtu.edu.cn".to_string()).unwrap();
|
||||
let data = job.recv().await;
|
||||
assert!(data.is_ok());
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue