use tact_client::Error;
#[test]
fn test_error_constructors() {
let err = Error::invalid_manifest(42, "unexpected token");
assert_eq!(
err.to_string(),
"Invalid manifest format at line 42: unexpected token"
);
let err = Error::missing_field("BuildConfig");
assert_eq!(err.to_string(), "Missing required field: BuildConfig");
let err = Error::cdn_exhausted("wow/config/1234");
assert_eq!(
err.to_string(),
"All CDN hosts exhausted for wow/config/1234"
);
let err = Error::file_not_found("/path/to/file.dat");
assert_eq!(err.to_string(), "File not found: /path/to/file.dat");
let err = Error::invalid_hash("not-a-valid-hash");
assert_eq!(err.to_string(), "Invalid hash format: not-a-valid-hash");
let err = Error::checksum_mismatch("abc123", "def456");
assert_eq!(
err.to_string(),
"Checksum verification failed: expected abc123, got def456"
);
}
#[test]
fn test_error_variants() {
let errors = vec![
Error::InvalidRegion("xyz".to_string()),
Error::UnsupportedProduct("unknown".to_string()),
Error::InvalidProtocolVersion,
Error::InvalidResponse,
Error::ConnectionTimeout {
host: "example.com".to_string(),
},
];
for err in errors {
assert!(!err.to_string().is_empty());
}
}
#[test]
fn test_error_debug() {
let err = Error::missing_field("test");
let debug_str = format!("{err:?}");
assert!(debug_str.contains("MissingField"));
assert!(debug_str.contains("test"));
}