Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
ibigbug committed Oct 12, 2024
1 parent 81cbffc commit 276c1c5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
7 changes: 2 additions & 5 deletions clash_lib/src/proxy/utils/test_utils/config_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ pub fn test_config_base_dir() -> PathBuf {

// load the config from test dir
// and return the dns resolver for the proxy
pub async fn load_config() -> anyhow::Result<(
crate::config::internal::config::Config,
Arc<dyn ClashResolver>,
)> {
pub async fn build_dns_resolver() -> anyhow::Result<Arc<dyn ClashResolver>> {
let root = root_dir();
let test_base_dir = test_config_base_dir();
let config_path = test_base_dir.join("ss.yaml").to_str().unwrap().to_owned();
Expand Down Expand Up @@ -55,5 +52,5 @@ pub async fn load_config() -> anyhow::Result<(
.await,
);

Ok((config, dns_resolver))
Ok(dns_resolver)
}
8 changes: 4 additions & 4 deletions clash_lib/src/proxy/utils/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub async fn ping_pong_test(
..Default::default()
};

let (_, resolver) = config_helper::load_config().await?;
let resolver = config_helper::build_dns_resolver().await?;

let listener = TcpListener::bind(format!("0.0.0.0:{}", port).as_str()).await?;

Expand Down Expand Up @@ -167,7 +167,7 @@ pub async fn ping_pong_udp_test(
..Default::default()
};

let (_, resolver) = config_helper::load_config().await?;
let resolver = config_helper::build_dns_resolver().await?;

let listener = UdpSocket::bind(format!("0.0.0.0:{}", port).as_str()).await?;
info!("target local server started at: {}", listener.local_addr()?);
Expand Down Expand Up @@ -242,7 +242,7 @@ pub async fn ping_pong_udp_test(
pub async fn latency_test(
handler: Arc<dyn OutboundHandler>,
) -> anyhow::Result<(u16, u16)> {
let (_, resolver) = config_helper::load_config().await?;
let resolver = config_helper::build_dns_resolver().await?;
let proxy_manager = ProxyManager::new(resolver.clone());
proxy_manager
.url_test(handler, "https://example.com", None)
Expand All @@ -259,7 +259,7 @@ pub async fn dns_test(handler: Arc<dyn OutboundHandler>) -> anyhow::Result<()> {
..Default::default()
};

let (_, resolver) = config_helper::load_config().await?;
let resolver = config_helper::build_dns_resolver().await?;

// we don't need the resolver, so it doesn't matter to create a casual one
let stream = handler.connect_datagram(&sess, resolver).await?;
Expand Down

0 comments on commit 276c1c5

Please sign in to comment.