72 lines
2.3 KiB
Rust
72 lines
2.3 KiB
Rust
//! Copyright (c) 2022-2026 GitDataAi All rights reserved.
|
|
|
|
use gitks::error::GitError;
|
|
|
|
#[test]
|
|
fn test_error_display_variants() {
|
|
let cases: Vec<(GitError, &str)> = vec![
|
|
(GitError::NotBareRepository, "not bare"),
|
|
(
|
|
GitError::CommandFailed {
|
|
status_code: Some(1),
|
|
stderr: "err".into(),
|
|
},
|
|
"command failed",
|
|
),
|
|
(GitError::UnsafeCommand("rm".into()), "unsafe"),
|
|
(GitError::ObjectNotFound("abc".into()), "object not found"),
|
|
(GitError::RefNotFound("main".into()), "reference not found"),
|
|
(GitError::ParseError("bad".into()), "parse error"),
|
|
(GitError::Gix("gix err".into()), "gix error"),
|
|
(GitError::RepoNotFound, "repository not found"),
|
|
(GitError::Internal("oops".into()), "internal error"),
|
|
(GitError::NotFound("x".into()), "not found"),
|
|
(GitError::InvalidOid("bad".into()), "invalid oid"),
|
|
(GitError::Locked("lock".into()), "locked"),
|
|
(
|
|
GitError::PermissionDenied("denied".into()),
|
|
"permission denied",
|
|
),
|
|
(GitError::AuthFailed("auth".into()), "authentication failed"),
|
|
(GitError::PayloadTooLarge("big".into()), "payload too large"),
|
|
(GitError::InvalidArgument("arg".into()), "invalid argument"),
|
|
];
|
|
|
|
for (err, keyword) in cases {
|
|
let msg = err.to_string();
|
|
assert!(
|
|
msg.to_lowercase().contains(keyword),
|
|
"error '{}' should contain '{}'",
|
|
msg,
|
|
keyword
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn test_error_is_debug() {
|
|
let err = GitError::Internal("test".into());
|
|
let debug = format!("{:?}", err);
|
|
assert!(debug.contains("Internal"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_io_error_conversion() {
|
|
let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file not found");
|
|
let git_err: GitError = io_err.into();
|
|
match git_err {
|
|
GitError::Io(_) => {}
|
|
other => panic!("expected Io variant, got: {:?}", other),
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn test_boxed_error_conversion() {
|
|
let boxed: Box<dyn std::error::Error + Send + Sync> = "test error".into();
|
|
let git_err: GitError = boxed.into();
|
|
match git_err {
|
|
GitError::Gix(msg) => assert!(msg.contains("test error")),
|
|
other => panic!("expected Gix variant, got: {:?}", other),
|
|
}
|
|
}
|