test: add insta snapshot test for storage error display format (#740) (#4001)

test: add insta snapshot test for storage error display format

Add snapshot test to detect unexpected changes in StorageError
display format. This catches output format regressions that
traditional assert tests might miss.

Refs #740
This commit is contained in:
Zhengchao An
2026-06-28 16:10:07 +08:00
committed by GitHub
parent 84cdf12083
commit ee82d6c026
5 changed files with 88 additions and 0 deletions
+1
View File
@@ -145,6 +145,7 @@ serial_test = { workspace = true }
opentelemetry_sdk = { workspace = true }
proptest = "1"
rcgen.workspace = true
insta = { workspace = true }
[build-dependencies]
shadow-rs = { workspace = true, features = ["build", "metadata"] }
+30
View File
@@ -1448,4 +1448,34 @@ mod tests {
assert_eq!(original_error, recovered_error);
}
}
#[test]
fn test_storage_error_display_snapshot() {
// Snapshot test to detect unexpected changes in error display format
let errors = vec![
StorageError::BucketNotFound("test-bucket".to_string()),
StorageError::ObjectNotFound("bucket".to_string(), "object".to_string()),
StorageError::VersionNotFound("bucket".to_string(), "object".to_string(), "v1".to_string()),
StorageError::InvalidUploadID("bucket".to_string(), "object".to_string(), "upload123".to_string()),
StorageError::DiskFull,
StorageError::FaultyDisk,
StorageError::FileNotFound,
StorageError::VolumeNotFound,
StorageError::ErasureReadQuorum,
StorageError::ErasureWriteQuorum,
StorageError::DecommissionAlreadyRunning,
StorageError::RebalanceAlreadyRunning,
StorageError::OperationCanceled,
StorageError::NamespaceLockQuorumUnavailable {
mode: "write",
bucket: "bucket".into(),
object: "object".into(),
required: 3,
achieved: 2,
},
];
let error_messages: Vec<String> = errors.iter().map(|e| e.to_string()).collect();
insta::assert_yaml_snapshot!("storage_error_display", error_messages);
}
}
@@ -0,0 +1,18 @@
---
source: crates/ecstore/src/error/mod.rs
expression: error_messages
---
- "Bucket not found: test-bucket"
- "Object not found: bucket/object"
- "Version not found: bucket/object-v1"
- "Invalid upload id: bucket/object-upload123"
- Disk full
- Faulty disk
- File not found
- Volume not found
- erasure read quorum
- erasure write quorum
- Decommission already running
- Rebalance already running
- Operation canceled
- "Namespace lock quorum unavailable for write lock on bucket/object: required 3, achieved 2"