mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-18 18:46:17 +00:00
fix: resolve all Clippy warnings across codebase - Fixed field reassignment warnings in ecstore/src/file_meta.rs by using struct initialization instead of default + field assignment - Fixed overly complex boolean expression in ecstore/src/utils/os/mod.rs by removing meaningless assertion - Replaced manual Default implementation with derive in crates/zip/src/lib.rs - Updated io::Error usage to use io::Error::other() instead of deprecated pattern - Removed useless assertions and clone-on-copy warnings - Fixed unwrap usage by replacing with expect() providing meaningful error messages - Fixed useless vec usage by using array repeat instead - All code now passes comprehensive Clippy check with --all-targets --all-features -- -D warnings
This commit is contained in:
@@ -98,11 +98,9 @@ mod tests {
|
||||
fn test_app_basic_constants() {
|
||||
// Test application basic constants
|
||||
assert_eq!(APP_NAME, "RustFs");
|
||||
assert!(!APP_NAME.is_empty(), "App name should not be empty");
|
||||
assert!(!APP_NAME.contains(' '), "App name should not contain spaces");
|
||||
|
||||
assert_eq!(VERSION, "0.0.1");
|
||||
assert!(!VERSION.is_empty(), "Version should not be empty");
|
||||
|
||||
assert_eq!(SERVICE_VERSION, "0.0.1");
|
||||
assert_eq!(VERSION, SERVICE_VERSION, "Version and service version should be consistent");
|
||||
@@ -117,13 +115,9 @@ mod tests {
|
||||
"Log level should be a valid tracing level"
|
||||
);
|
||||
|
||||
assert_eq!(USE_STDOUT, false);
|
||||
|
||||
assert_eq!(SAMPLE_RATIO, 1.0);
|
||||
assert!(SAMPLE_RATIO >= 0.0 && SAMPLE_RATIO <= 1.0, "Sample ratio should be between 0.0 and 1.0");
|
||||
|
||||
assert_eq!(METER_INTERVAL, 30);
|
||||
assert!(METER_INTERVAL > 0, "Meter interval should be positive");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -140,23 +134,17 @@ mod tests {
|
||||
fn test_connection_constants() {
|
||||
// Test connection related constants
|
||||
assert_eq!(MAX_CONNECTIONS, 100);
|
||||
assert!(MAX_CONNECTIONS > 0, "Max connections should be positive");
|
||||
assert!(MAX_CONNECTIONS <= 10000, "Max connections should be reasonable");
|
||||
|
||||
assert_eq!(DEFAULT_TIMEOUT_MS, 3000);
|
||||
assert!(DEFAULT_TIMEOUT_MS > 0, "Timeout should be positive");
|
||||
assert!(DEFAULT_TIMEOUT_MS >= 1000, "Timeout should be at least 1 second");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_security_constants() {
|
||||
// Test security related constants
|
||||
assert_eq!(DEFAULT_ACCESS_KEY, "rustfsadmin");
|
||||
assert!(!DEFAULT_ACCESS_KEY.is_empty(), "Access key should not be empty");
|
||||
assert!(DEFAULT_ACCESS_KEY.len() >= 8, "Access key should be at least 8 characters");
|
||||
|
||||
assert_eq!(DEFAULT_SECRET_KEY, "rustfsadmin");
|
||||
assert!(!DEFAULT_SECRET_KEY.is_empty(), "Secret key should not be empty");
|
||||
assert!(DEFAULT_SECRET_KEY.len() >= 8, "Secret key should be at least 8 characters");
|
||||
|
||||
// In production environment, access key and secret key should be different
|
||||
@@ -169,7 +157,6 @@ mod tests {
|
||||
// Test file path related constants
|
||||
assert_eq!(DEFAULT_OBS_CONFIG, "./deploy/config/obs.toml");
|
||||
assert!(DEFAULT_OBS_CONFIG.ends_with(".toml"), "Config file should be TOML format");
|
||||
assert!(!DEFAULT_OBS_CONFIG.is_empty(), "Config path should not be empty");
|
||||
|
||||
assert_eq!(RUSTFS_TLS_KEY, "rustfs_key.pem");
|
||||
assert!(RUSTFS_TLS_KEY.ends_with(".pem"), "TLS key should be PEM format");
|
||||
@@ -182,12 +169,8 @@ mod tests {
|
||||
fn test_port_constants() {
|
||||
// Test port related constants
|
||||
assert_eq!(DEFAULT_PORT, 9000);
|
||||
assert!(DEFAULT_PORT > 1024, "Default port should be above reserved range");
|
||||
// u16 type automatically ensures port is in valid range (0-65535)
|
||||
|
||||
assert_eq!(DEFAULT_CONSOLE_PORT, 9002);
|
||||
assert!(DEFAULT_CONSOLE_PORT > 1024, "Console port should be above reserved range");
|
||||
// u16 type automatically ensures port is in valid range (0-65535)
|
||||
|
||||
assert_ne!(DEFAULT_PORT, DEFAULT_CONSOLE_PORT, "Main port and console port should be different");
|
||||
}
|
||||
@@ -256,12 +239,14 @@ mod tests {
|
||||
assert!(SAMPLE_RATIO.is_finite(), "Sample ratio should be finite");
|
||||
assert!(!SAMPLE_RATIO.is_nan(), "Sample ratio should not be NaN");
|
||||
|
||||
assert!(METER_INTERVAL < u64::MAX, "Meter interval should be reasonable");
|
||||
assert!(MAX_CONNECTIONS < usize::MAX, "Max connections should be reasonable");
|
||||
assert!(DEFAULT_TIMEOUT_MS < u64::MAX, "Timeout should be reasonable");
|
||||
// All these are const values, so range checks are redundant
|
||||
// assert!(METER_INTERVAL < u64::MAX, "Meter interval should be reasonable");
|
||||
// assert!(MAX_CONNECTIONS < usize::MAX, "Max connections should be reasonable");
|
||||
// assert!(DEFAULT_TIMEOUT_MS < u64::MAX, "Timeout should be reasonable");
|
||||
|
||||
assert!(DEFAULT_PORT != 0, "Default port should not be zero");
|
||||
assert!(DEFAULT_CONSOLE_PORT != 0, "Console port should not be zero");
|
||||
// These are const non-zero values, so zero checks are redundant
|
||||
// assert!(DEFAULT_PORT != 0, "Default port should not be zero");
|
||||
// assert!(DEFAULT_CONSOLE_PORT != 0, "Console port should not be zero");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -317,7 +317,8 @@ mod tests {
|
||||
fn test_default_config_file_constant() {
|
||||
// Test that the constant is properly defined
|
||||
assert_eq!(DEFAULT_CONFIG_FILE, "event");
|
||||
assert!(!DEFAULT_CONFIG_FILE.is_empty(), "Config file name should not be empty");
|
||||
// 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");
|
||||
}
|
||||
|
||||
@@ -76,12 +76,13 @@ mod tests {
|
||||
let config = ObservabilityConfig::new();
|
||||
|
||||
// Test OTEL default values
|
||||
if let Some(use_stdout) = config.otel.use_stdout {
|
||||
assert!(use_stdout == true || use_stdout == false, "use_stdout should be a valid boolean");
|
||||
if let Some(_use_stdout) = config.otel.use_stdout {
|
||||
// Test boolean values - any boolean value is valid
|
||||
// assert!(use_stdout || !use_stdout, "use_stdout should be a valid boolean");
|
||||
}
|
||||
|
||||
if let Some(sample_ratio) = config.otel.sample_ratio {
|
||||
assert!(sample_ratio >= 0.0 && sample_ratio <= 1.0, "Sample ratio should be between 0.0 and 1.0");
|
||||
assert!((0.0..=1.0).contains(&sample_ratio), "Sample ratio should be between 0.0 and 1.0");
|
||||
}
|
||||
|
||||
if let Some(meter_interval) = config.otel.meter_interval {
|
||||
|
||||
@@ -343,7 +343,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_error_downcast() {
|
||||
// 测试错误的向下转型
|
||||
let io_error = io::Error::new(io::ErrorKind::Other, "test error");
|
||||
let io_error = io::Error::other("test error");
|
||||
let converted: Error = io_error.into();
|
||||
|
||||
// 验证可以获取源错误
|
||||
@@ -358,7 +358,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_error_chain_depth() {
|
||||
// 测试错误链的深度
|
||||
let root_cause = io::Error::new(io::ErrorKind::Other, "root cause");
|
||||
let root_cause = io::Error::other("root cause");
|
||||
let converted: Error = root_cause.into();
|
||||
|
||||
let mut depth = 0;
|
||||
@@ -411,8 +411,8 @@ mod tests {
|
||||
|
||||
// Debug 输出通常包含更多信息,但不是绝对的
|
||||
// 这里我们只验证两者都有内容即可
|
||||
assert!(debug_str.len() > 0);
|
||||
assert!(display_str.len() > 0);
|
||||
assert!(!debug_str.is_empty());
|
||||
assert!(!display_str.is_empty());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ pub fn load_private_key(filename: &str) -> io::Result<PrivateKeyDer<'static>> {
|
||||
|
||||
/// error function
|
||||
pub fn certs_error(err: String) -> Error {
|
||||
Error::new(io::ErrorKind::Other, err)
|
||||
Error::other(err)
|
||||
}
|
||||
|
||||
/// Load all certificates and private keys in the directory
|
||||
|
||||
+4
-10
@@ -21,20 +21,15 @@ pub enum CompressionFormat {
|
||||
Unknown,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub enum CompressionLevel {
|
||||
Fastest,
|
||||
Best,
|
||||
#[default]
|
||||
Default,
|
||||
Level(u32),
|
||||
}
|
||||
|
||||
impl Default for CompressionLevel {
|
||||
fn default() -> Self {
|
||||
CompressionLevel::Default
|
||||
}
|
||||
}
|
||||
|
||||
impl CompressionFormat {
|
||||
/// Identify compression format from file extension
|
||||
pub fn from_extension(ext: &str) -> Self {
|
||||
@@ -679,7 +674,7 @@ mod tests {
|
||||
async move {
|
||||
if invocation_number == 0 {
|
||||
// First invocation returns an error
|
||||
Err(io::Error::new(io::ErrorKind::Other, "Simulated callback error"))
|
||||
Err(io::Error::other("Simulated callback error"))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
@@ -765,8 +760,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
// 如果能执行到这里,说明性能是可接受的
|
||||
assert!(true, "Extension parsing performance test completed");
|
||||
// Extension parsing performance test completed
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user