fix: handle Windows paths in pre-commit tests (#2974)

Co-authored-by: houseme <housemecn@gmail.com>
This commit is contained in:
Henry Guo
2026-05-15 22:04:51 +08:00
committed by GitHub
parent 738fb86611
commit bca8b08c2b
15 changed files with 134 additions and 46 deletions
+17 -9
View File
@@ -605,6 +605,10 @@ mod tests {
};
use rustfs_ecstore::config::KVS;
fn absolute_test_path(path: &str) -> String {
std::env::temp_dir().join(path).to_string_lossy().into_owned()
}
fn amqp_base_config() -> KVS {
let mut config = KVS::new();
config.insert(AMQP_URL.to_string(), "amqp://127.0.0.1:5672/%2f".to_string());
@@ -787,8 +791,9 @@ mod tests {
#[test]
fn build_mysql_args_applies_defaults() {
let args = build_mysql_args(&mysql_base_config(), "/custom/queue", TargetType::NotifyEvent).expect("valid mysql args");
assert_eq!(args.queue_dir, "/custom/queue");
let queue_dir = absolute_test_path("custom-queue");
let args = build_mysql_args(&mysql_base_config(), &queue_dir, TargetType::NotifyEvent).expect("valid mysql args");
assert_eq!(args.queue_dir, queue_dir);
assert_eq!(args.queue_limit, 100000);
assert_eq!(args.max_open_connections, 2);
}
@@ -846,7 +851,7 @@ mod tests {
let err = validate_mysql_config(&config, "").expect_err("relative tls_ca should fail");
assert!(err.to_string().contains("tls_ca must be an absolute path"));
config.insert(MYSQL_TLS_CA.to_string(), "/etc/ssl/mysql/ca.pem".to_string());
config.insert(MYSQL_TLS_CA.to_string(), absolute_test_path("mysql-ca.pem"));
config.insert(MYSQL_TLS_CLIENT_CERT.to_string(), "client.pem".to_string());
config.insert(MYSQL_TLS_CLIENT_KEY.to_string(), "client.key".to_string());
@@ -857,14 +862,17 @@ mod tests {
#[test]
fn build_mysql_args_accepts_absolute_tls_paths() {
let mut config = mysql_base_config();
config.insert(MYSQL_TLS_CA.to_string(), "/etc/ssl/mysql/ca.pem".to_string());
config.insert(MYSQL_TLS_CLIENT_CERT.to_string(), "/etc/ssl/mysql/client.pem".to_string());
config.insert(MYSQL_TLS_CLIENT_KEY.to_string(), "/etc/ssl/mysql/client.key".to_string());
let tls_ca = absolute_test_path("mysql-ca.pem");
let tls_client_cert = absolute_test_path("mysql-client.pem");
let tls_client_key = absolute_test_path("mysql-client.key");
config.insert(MYSQL_TLS_CA.to_string(), tls_ca.clone());
config.insert(MYSQL_TLS_CLIENT_CERT.to_string(), tls_client_cert.clone());
config.insert(MYSQL_TLS_CLIENT_KEY.to_string(), tls_client_key.clone());
let args = build_mysql_args(&config, "", TargetType::NotifyEvent).expect("absolute mysql TLS paths should pass");
assert_eq!(args.tls_ca, "/etc/ssl/mysql/ca.pem");
assert_eq!(args.tls_client_cert, "/etc/ssl/mysql/client.pem");
assert_eq!(args.tls_client_key, "/etc/ssl/mysql/client.key");
assert_eq!(args.tls_ca, tls_ca);
assert_eq!(args.tls_client_cert, tls_client_cert);
assert_eq!(args.tls_client_key, tls_client_key);
}
fn redis_base_config() -> KVS {
+8 -4
View File
@@ -832,6 +832,10 @@ where
mod tests {
use super::*;
fn absolute_test_path(path: &str) -> String {
std::env::temp_dir().join(path).to_string_lossy().into_owned()
}
#[test]
fn parse_dsn_format() {
let dsn = MySqlDsn::parse("rustfs:secret123@tcp(mysql.example.com:3306)/rustfs_events").expect("valid DSN");
@@ -1189,10 +1193,10 @@ mod tests {
dsn_string: "rustfs:password@tcp(127.0.0.1:3306)/db".to_string(),
table: "events".to_string(),
format: "access".to_string(),
tls_ca: "/etc/ssl/mysql/ca.pem".to_string(),
tls_client_cert: "/etc/ssl/mysql/client.pem".to_string(),
tls_client_key: "/etc/ssl/mysql/client.key".to_string(),
queue_dir: "/tmp".to_string(),
tls_ca: absolute_test_path("mysql-ca.pem"),
tls_client_cert: absolute_test_path("mysql-client.pem"),
tls_client_key: absolute_test_path("mysql-client.key"),
queue_dir: absolute_test_path("mysql-queue"),
queue_limit: 100,
max_open_connections: 2,
target_type: TargetType::NotifyEvent,
+5 -1
View File
@@ -730,6 +730,10 @@ mod tests {
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::TcpListener;
fn absolute_test_path(path: &str) -> String {
std::env::temp_dir().join(path).to_string_lossy().into_owned()
}
fn base_args() -> RedisArgs {
RedisArgs {
enable: true,
@@ -782,7 +786,7 @@ mod tests {
url: Url::parse("rediss://127.0.0.1:6379").unwrap(),
tls: RedisTlsConfig {
policy: Some(RedisTlsPolicy::CustomCa),
ca_path: "/tmp/ca.pem".to_string(),
ca_path: absolute_test_path("redis-ca.pem"),
..RedisTlsConfig::default()
},
..base_args()