From 21c472bfbfe20a8cbdfbd8d1fb5f4206d068f97c Mon Sep 17 00:00:00 2001 From: dev0 Date: Mon, 6 Nov 2023 05:51:37 +1100 Subject: [PATCH] fix tests --- .../app/remote_content_manager/providers/fetcher.rs | 10 +++++----- .../remote_content_manager/providers/http_vehicle.rs | 8 ++------ clash_lib/src/common/http.rs | 2 ++ 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/clash_lib/src/app/remote_content_manager/providers/fetcher.rs b/clash_lib/src/app/remote_content_manager/providers/fetcher.rs index 6e9848c08..2c97b0b23 100644 --- a/clash_lib/src/app/remote_content_manager/providers/fetcher.rs +++ b/clash_lib/src/app/remote_content_manager/providers/fetcher.rs @@ -253,15 +253,15 @@ mod tests { let tx1 = tx.clone(); let mut mock_vehicle = MockProviderVehicle::new(); - let mock_file = "/tmp/mock_provider_vehicle"; - if Path::new(mock_file).exists() { - std::fs::remove_file(mock_file).unwrap(); + let mock_file = std::env::temp_dir().join("mock_provider_vehicle"); + if Path::new(mock_file.to_str().unwrap()).exists() { + std::fs::remove_file(&mock_file).unwrap(); } - std::fs::write(mock_file, vec![1, 2, 3]).unwrap(); + std::fs::write(&mock_file, vec![1, 2, 3]).unwrap(); mock_vehicle .expect_path() - .return_const(mock_file.to_owned()); + .return_const(mock_file.to_str().unwrap().to_owned()); mock_vehicle.expect_read().returning(|| Ok(vec![4, 5, 6])); mock_vehicle .expect_typ() diff --git a/clash_lib/src/app/remote_content_manager/providers/http_vehicle.rs b/clash_lib/src/app/remote_content_manager/providers/http_vehicle.rs index 32d1afa5e..b2ca4b8ab 100644 --- a/clash_lib/src/app/remote_content_manager/providers/http_vehicle.rs +++ b/clash_lib/src/app/remote_content_manager/providers/http_vehicle.rs @@ -74,13 +74,9 @@ mod tests { let u = "https://httpbin.yba.dev/base64/SFRUUEJJTiBpcyBhd2Vzb21l" .parse::() .unwrap(); + let p = std::env::temp_dir().join("test_http_vehicle"); let r = Arc::new(Resolver::new_default().await); - let v = super::Vehicle::new( - u, - "/tmp/test_http_vehicle", - None, - r.clone() as ThreadSafeDNSResolver, - ); + let v = super::Vehicle::new(u, p, None, r.clone() as ThreadSafeDNSResolver); let data = v.read().await.unwrap(); assert_eq!(str::from_utf8(&data).unwrap(), "HTTPBIN is awesome"); diff --git a/clash_lib/src/common/http.rs b/clash_lib/src/common/http.rs index 159a0f11f..e5a1de2b0 100644 --- a/clash_lib/src/common/http.rs +++ b/clash_lib/src/common/http.rs @@ -73,6 +73,8 @@ pub fn new_http_client(dns_resolver: ThreadSafeDNSResolver) -> std::io::Result(connector))