Merge pull request #437 from rustfs/feat/add-formatting-rules-and-type-inference

feat: add comprehensive formatting rules and type inference guidelines
This commit is contained in:
安正超
2025-05-28 16:20:59 +08:00
committed by GitHub
28 changed files with 792 additions and 383 deletions
+11 -5
View File
@@ -94,7 +94,10 @@ mod tests {
// Test event config properties
assert!(!config.event.store_path.is_empty(), "Store path should not be empty");
assert!(config.event.channel_capacity >= 1000, "Channel capacity should be reasonable for production");
assert!(
config.event.channel_capacity >= 1000,
"Channel capacity should be reasonable for production"
);
// Test that store path is a valid path format
let store_path = &config.event.store_path;
@@ -106,13 +109,13 @@ mod tests {
match adapter {
crate::event::adapters::AdapterConfig::Webhook(_) => {
// Webhook adapter should be properly configured
},
}
crate::event::adapters::AdapterConfig::Kafka(_) => {
// Kafka adapter should be properly configured
},
}
crate::event::adapters::AdapterConfig::Mqtt(_) => {
// MQTT adapter should be properly configured
},
}
}
}
}
@@ -153,7 +156,10 @@ mod tests {
// Test that observability config has Debug trait
let observability_debug = format!("{:?}", config.observability);
assert!(!observability_debug.is_empty(), "Observability config should have debug output");
assert!(observability_debug.contains("ObservabilityConfig"), "Debug output should contain type name");
assert!(
observability_debug.contains("ObservabilityConfig"),
"Debug output should contain type name"
);
// Test that event config has Debug trait
let event_debug = format!("{:?}", config.event);
+15 -6
View File
@@ -53,7 +53,10 @@ mod tests {
// Verify store path is set
assert!(!config.store_path.is_empty(), "Store path should not be empty");
assert!(config.store_path.contains("event-notification"), "Store path should contain event-notification");
assert!(
config.store_path.contains("event-notification"),
"Store path should contain event-notification"
);
// Verify channel capacity is reasonable
assert_eq!(config.channel_capacity, 10000, "Channel capacity should be 10000");
@@ -153,7 +156,10 @@ mod tests {
assert!(!debug_str.is_empty(), "Debug output should not be empty");
assert!(debug_str.contains("NotifierConfig"), "Debug output should contain struct name");
assert!(debug_str.contains("store_path"), "Debug output should contain store_path field");
assert!(debug_str.contains("channel_capacity"), "Debug output should contain channel_capacity field");
assert!(
debug_str.contains("channel_capacity"),
"Debug output should contain channel_capacity field"
);
assert!(debug_str.contains("adapters"), "Debug output should contain adapters field");
}
@@ -217,13 +223,13 @@ mod tests {
match adapter {
AdapterConfig::Webhook(_) => {
// Webhook adapter should be properly configured
},
}
AdapterConfig::Kafka(_) => {
// Kafka adapter should be properly configured
},
}
AdapterConfig::Mqtt(_) => {
// MQTT adapter should be properly configured
},
}
}
}
}
@@ -320,6 +326,9 @@ mod tests {
// DEFAULT_CONFIG_FILE is a const, so is_empty() check is redundant
// assert!(!DEFAULT_CONFIG_FILE.is_empty(), "Config file name should not be empty");
assert!(!DEFAULT_CONFIG_FILE.contains('/'), "Config file name should not contain path separators");
assert!(!DEFAULT_CONFIG_FILE.contains('\\'), "Config file name should not contain Windows path separators");
assert!(
!DEFAULT_CONFIG_FILE.contains('\\'),
"Config file name should not contain Windows path separators"
);
}
}
+29 -21
View File
@@ -191,7 +191,7 @@ mod tests {
use std::fs;
use tempfile::TempDir;
#[test]
#[test]
fn test_certs_error_function() {
let error_msg = "Test error message";
let error = certs_error(error_msg.to_string());
@@ -210,7 +210,7 @@ mod tests {
assert!(error.to_string().contains("failed to open"));
}
#[test]
#[test]
fn test_load_private_key_file_not_found() {
let result = load_private_key("non_existent_key.pem");
assert!(result.is_err());
@@ -233,7 +233,7 @@ mod tests {
assert!(error.to_string().contains("No valid certificate was found"));
}
#[test]
#[test]
fn test_load_certs_invalid_format() {
let temp_dir = TempDir::new().unwrap();
let cert_path = temp_dir.path().join("invalid.pem");
@@ -259,7 +259,7 @@ mod tests {
assert!(error.to_string().contains("no private key found"));
}
#[test]
#[test]
fn test_load_private_key_invalid_format() {
let temp_dir = TempDir::new().unwrap();
let key_path = temp_dir.path().join("invalid_key.pem");
@@ -281,7 +281,7 @@ mod tests {
assert!(error.to_string().contains("does not exist or is not a directory"));
}
#[test]
#[test]
fn test_load_all_certs_from_directory_empty() {
let temp_dir = TempDir::new().unwrap();
@@ -315,7 +315,7 @@ mod tests {
assert!(result.is_err());
}
#[test]
#[test]
fn test_load_cert_key_pair_missing_key() {
let temp_dir = TempDir::new().unwrap();
let cert_path = temp_dir.path().join("test_cert.pem");
@@ -355,12 +355,12 @@ mod tests {
fn test_path_handling_edge_cases() {
// Test with various path formats
let path_cases = vec![
"", // Empty path
".", // Current directory
"..", // Parent directory
"/", // Root directory (Unix)
"relative/path", // Relative path
"/absolute/path", // Absolute path
"", // Empty path
".", // Current directory
"..", // Parent directory
"/", // Root directory (Unix)
"relative/path", // Relative path
"/absolute/path", // Absolute path
];
for path in path_cases {
@@ -396,7 +396,10 @@ mod tests {
// Should fail because no certificates found
let result = load_all_certs_from_directory(temp_dir.path().to_str().unwrap());
assert!(result.is_err());
assert!(result.unwrap_err().to_string().contains("No valid certificate/private key pair found"));
assert!(result
.unwrap_err()
.to_string()
.contains("No valid certificate/private key pair found"));
}
#[test]
@@ -409,7 +412,10 @@ mod tests {
let result = load_all_certs_from_directory(unicode_dir.to_str().unwrap());
assert!(result.is_err());
assert!(result.unwrap_err().to_string().contains("No valid certificate/private key pair found"));
assert!(result
.unwrap_err()
.to_string()
.contains("No valid certificate/private key pair found"));
}
#[test]
@@ -420,14 +426,16 @@ mod tests {
let temp_dir = TempDir::new().unwrap();
let dir_path = Arc::new(temp_dir.path().to_string_lossy().to_string());
let handles: Vec<_> = (0..5).map(|_| {
let path = Arc::clone(&dir_path);
thread::spawn(move || {
let result = load_all_certs_from_directory(&path);
// All should fail since directory is empty
assert!(result.is_err());
let handles: Vec<_> = (0..5)
.map(|_| {
let path = Arc::clone(&dir_path);
thread::spawn(move || {
let result = load_all_certs_from_directory(&path);
// All should fail since directory is empty
assert!(result.is_err());
})
})
}).collect();
.collect();
for handle in handles {
handle.join().expect("Thread should complete successfully");