test: prune redundant cases and add high-risk coverage across crates (#4208)

Remove or consolidate 57 test cases that cannot catch regressions
(literal-constant asserts, construct-then-assert, derived-serde
round-trips, near-duplicate env/getter matrices) in common, config,
iam, madmin, and object-capacity, keeping all wire-format and
error-path guards. Add 13 tests for previously uncovered high-risk
behavior: filemeta version-sort determinism and merge resilience to
garbage headers, zip extraction path-traversal rejection and exact
limit boundaries, JWT tampered-signature rejection, and the bytes
variant of dual-key (rustfs/minio) metadata fallback and precedence.

Test-only change; no production code touched.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Zhengchao An
2026-07-03 00:35:37 +08:00
committed by GitHub
parent dd6b5525e4
commit 9dfeffc4c1
11 changed files with 256 additions and 748 deletions
-79
View File
@@ -325,85 +325,6 @@ pub const MI_B: usize = 1024 * KI_B;
mod tests {
use super::*;
#[test]
fn test_app_basic_constants() {
// Test application basic constants
assert_eq!(APP_NAME, "RustFS");
assert!(!APP_NAME.contains(' '), "App name should not contain spaces");
assert_eq!(VERSION, "1.0.0");
assert_eq!(SERVICE_VERSION, "1.0.0");
assert_eq!(VERSION, SERVICE_VERSION, "Version and service version should be consistent");
}
#[test]
fn test_logging_constants() {
// Test logging related constants
assert_eq!(DEFAULT_LOG_LEVEL, "error");
assert!(
["trace", "debug", "info", "warn", "error"].contains(&DEFAULT_LOG_LEVEL),
"Log level should be a valid tracing level"
);
assert_eq!(SAMPLE_RATIO, 1.0);
assert_eq!(METER_INTERVAL, 30);
}
#[test]
fn test_environment_constants() {
// Test environment related constants
assert_eq!(ENVIRONMENT, "production");
assert_eq!(ENV_RUSTFS_LICENSE_PUBLIC_KEY, "RUSTFS_LICENSE_PUBLIC_KEY");
assert!(
["development", "staging", "production", "test"].contains(&ENVIRONMENT),
"Environment should be a standard environment name"
);
}
#[test]
fn test_file_path_constants() {
assert_eq!(RUSTFS_TLS_KEY, "rustfs_key.pem");
assert!(RUSTFS_TLS_KEY.ends_with(".pem"), "TLS key should be PEM format");
assert_eq!(RUSTFS_TLS_CERT, "rustfs_cert.pem");
assert!(RUSTFS_TLS_CERT.ends_with(".pem"), "TLS cert should be PEM format");
}
#[test]
fn test_port_constants() {
// Test port related constants
assert_eq!(DEFAULT_PORT, 9000);
assert_eq!(DEFAULT_CONSOLE_PORT, 9001);
assert_ne!(DEFAULT_PORT, DEFAULT_CONSOLE_PORT, "Main port and console port should be different");
}
#[test]
fn test_address_constants() {
// Test address related constants
assert_eq!(DEFAULT_ADDRESS, ":9000");
assert!(DEFAULT_ADDRESS.starts_with(':'), "Address should start with colon");
assert!(
DEFAULT_ADDRESS.contains(&DEFAULT_PORT.to_string()),
"Address should contain the default port"
);
assert_eq!(DEFAULT_CONSOLE_ADDRESS, ":9001");
assert!(DEFAULT_CONSOLE_ADDRESS.starts_with(':'), "Console address should start with colon");
assert!(
DEFAULT_CONSOLE_ADDRESS.contains(&DEFAULT_CONSOLE_PORT.to_string()),
"Console address should contain the console port"
);
assert_ne!(
DEFAULT_ADDRESS, DEFAULT_CONSOLE_ADDRESS,
"Main address and console address should be different"
);
}
#[test]
fn test_const_str_concat_functionality() {
// Test const_str::concat macro functionality
-16
View File
@@ -145,20 +145,4 @@ mod tests {
assert_eq!(ENV_CAPACITY_MAX_TIMEOUT, "RUSTFS_CAPACITY_MAX_TIMEOUT");
assert_eq!(ENV_CAPACITY_STALL_TIMEOUT, "RUSTFS_CAPACITY_STALL_TIMEOUT");
}
#[test]
fn test_default_values() {
assert_eq!(DEFAULT_SCHEDULED_UPDATE_INTERVAL_SECS, 120);
assert_eq!(DEFAULT_WRITE_TRIGGER_DELAY_SECS, 5);
assert_eq!(DEFAULT_WRITE_FREQUENCY_THRESHOLD, 5);
assert_eq!(DEFAULT_FAST_UPDATE_THRESHOLD_SECS, 30);
assert_eq!(DEFAULT_MAX_FILES_THRESHOLD, 200_000);
assert_eq!(DEFAULT_STAT_TIMEOUT_SECS, 3);
assert_eq!(DEFAULT_SAMPLE_RATE, 200);
assert_eq!(DEFAULT_CAPACITY_METRICS_INTERVAL_SECS, 600);
assert_eq!(DEFAULT_CAPACITY_MAX_SYMLINK_DEPTH, 3);
assert_eq!(DEFAULT_CAPACITY_MIN_TIMEOUT_SECS, 2);
assert_eq!(DEFAULT_CAPACITY_MAX_TIMEOUT_SECS, 15);
assert_eq!(DEFAULT_CAPACITY_STALL_TIMEOUT_SECS, 20);
}
}
-7
View File
@@ -45,13 +45,6 @@ mod tests {
use super::*;
use crate::MI_B;
#[test]
fn test_default_values() {
assert_eq!(DEFAULT_BUFFER_MIN_SIZE, 65536); // 64KB
assert_eq!(DEFAULT_BUFFER_MAX_SIZE, 1048576); // 1MB
assert_eq!(DEFAULT_BUFFER_UNKNOWN_SIZE, 262144); // 256KB
}
#[test]
fn test_constants() {
assert_eq!(KI_B, 1024);