Skip to content

Commit 1482bb4

Browse files
tests: do not use std::fs in async tests
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
1 parent ef86e56 commit 1482bb4

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

tests/integration_test.rs

+27-14
Original file line numberDiff line numberDiff line change
@@ -682,10 +682,14 @@ async fn test_detect_certificate_rotation() {
682682
let first_tls_data_client = create_cert(hostname1);
683683
let second_tls_data_client = create_cert(hostname1);
684684

685-
std::fs::write(&cert_file, tls_data1.cert).unwrap();
686-
std::fs::write(&key_file, tls_data1.key).unwrap();
687-
std::fs::write(&first_client_ca, first_tls_data_client.cert.clone()).unwrap();
688-
std::fs::write(&second_client_ca, second_tls_data_client.cert.clone()).unwrap();
685+
fs::write(&cert_file, tls_data1.cert).await.unwrap();
686+
fs::write(&key_file, tls_data1.key).await.unwrap();
687+
fs::write(&first_client_ca, first_tls_data_client.cert.clone())
688+
.await
689+
.unwrap();
690+
fs::write(&second_client_ca, second_tls_data_client.cert.clone())
691+
.await
692+
.unwrap();
689693

690694
let mut config = default_test_config();
691695
config.tls_config = Some(policy_server::config::TlsConfig {
@@ -728,7 +732,7 @@ async fn test_detect_certificate_rotation() {
728732
let tls_data2 = create_cert(hostname2);
729733

730734
// write only the cert file
731-
std::fs::write(&cert_file, tls_data2.cert.clone()).unwrap();
735+
fs::write(&cert_file, tls_data2.cert.clone()).await.unwrap();
732736

733737
// give inotify some time to ensure it detected the cert change
734738
tokio::time::sleep(std::time::Duration::from_secs(4)).await;
@@ -739,7 +743,7 @@ async fn test_detect_certificate_rotation() {
739743
.expect("certificate should not have been changed");
740744

741745
// write only the key file
742-
std::fs::write(&key_file, tls_data2.key.clone()).unwrap();
746+
fs::write(&key_file, tls_data2.key.clone()).await.unwrap();
743747

744748
// give inotify some time to ensure it detected the cert change,
745749
// also give axum some time to complete the certificate reload
@@ -752,15 +756,19 @@ async fn test_detect_certificate_rotation() {
752756
let first_tls_data_client2 = create_cert(hostname2);
753757

754758
// write only the cert file
755-
std::fs::write(&first_client_ca, first_tls_data_client2.cert.clone()).unwrap();
759+
fs::write(&first_client_ca, first_tls_data_client2.cert.clone())
760+
.await
761+
.unwrap();
756762

757763
// give inotify some time to ensure it detected the cert change
758764
tokio::time::sleep(std::time::Duration::from_secs(4)).await;
759765

760766
let second_tls_data_client2 = create_cert(hostname2);
761767

762768
// write only the cert file
763-
std::fs::write(&second_client_ca, second_tls_data_client2.cert.clone()).unwrap();
769+
fs::write(&second_client_ca, second_tls_data_client2.cert.clone())
770+
.await
771+
.unwrap();
764772

765773
// give inotify some time to ensure it detected the cert change
766774
tokio::time::sleep(std::time::Duration::from_secs(4)).await;
@@ -1018,26 +1026,31 @@ async fn test_tls(
10181026
let key_file = certs_dir.path().join("policy-server-key.pem");
10191027

10201028
if let Some(ref tls_data) = server_tls_data {
1021-
std::fs::write(&cert_file, tls_data.cert.clone()).unwrap();
1022-
std::fs::write(&key_file, tls_data.key.clone()).unwrap();
1029+
fs::write(&cert_file, tls_data.cert.clone()).await.unwrap();
1030+
fs::write(&key_file, tls_data.key.clone()).await.unwrap();
10231031
}
10241032

10251033
// Client CA pem file, cert data and key data
10261034
let clients_cas_info: Vec<(PathBuf, String, String)> =
10271035
if let Some(ref tls_data) = client_tls_data {
1028-
tls_data
1036+
let tls_data: Vec<(PathBuf, String, String)> = tls_data
10291037
.iter()
10301038
.enumerate()
10311039
.map(|(i, tls_data)| {
10321040
let client_ca = certs_dir
10331041
.path()
10341042
.join(format!("client_cert_{}.pem", i))
10351043
.to_owned();
1036-
std::fs::write(&client_ca, tls_data.cert.clone())
1037-
.expect("failed to write client CA file");
1044+
10381045
(client_ca, tls_data.cert.clone(), tls_data.key.clone())
10391046
})
1040-
.collect()
1047+
.collect();
1048+
1049+
for (client_ca, cert, _) in &tls_data {
1050+
fs::write(&client_ca, cert.clone()).await.unwrap();
1051+
}
1052+
1053+
tls_data
10411054
} else {
10421055
vec![]
10431056
};

0 commit comments

Comments
 (0)