Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ibigbug committed Nov 5, 2023
1 parent 1cb0992 commit 21c472b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
10 changes: 5 additions & 5 deletions clash_lib/src/app/remote_content_manager/providers/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,9 @@ mod tests {
let u = "https://httpbin.yba.dev/base64/SFRUUEJJTiBpcyBhd2Vzb21l"
.parse::<Uri>()
.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");
Expand Down
2 changes: 2 additions & 0 deletions clash_lib/src/common/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ pub fn new_http_client(dns_resolver: ThreadSafeDNSResolver) -> std::io::Result<H
let mut ssl = SslConnector::builder(SslMethod::tls()).map_err(map_io_error)?;
ssl.set_alpn_protos(b"\x02h2\x08http/1.1")
.map_err(map_io_error)?;
#[cfg(target_os = "windows")]
ssl.set_verify(boring::ssl::SslVerifyMode::NONE); // TODO: verify certificate

let connector = HttpsConnector::with_connector(connector, ssl).map_err(map_io_error)?;
Ok(hyper::Client::builder().build::<_, hyper::Body>(connector))
Expand Down

0 comments on commit 21c472b

Please sign in to comment.