Skip to content

Commit

Permalink
[#132] Error mod.rs 테스트코드 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
myyrakle committed Jul 23, 2024
1 parent 1aa4a98 commit 4b32768
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/errors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,31 @@ impl ToString for RRDBError {
}
}
}

#[cfg(test)]
mod tests {
use predule::{ExecuteError, IntoError, LexingError, ParsingError, ServerError, TypeError};

use super::*;

#[test]
fn test_rrdb_error_to_string() {
let error = ExecuteError::wrap("test");
assert!(error.to_string().contains("test"));

let error = IntoError::wrap("test");
assert!(error.to_string().contains("test"));

let error = LexingError::wrap("test");
assert!(error.to_string().contains("test"));

let error = ParsingError::wrap("test");
assert!(error.to_string().contains("test"));

let error = ServerError::wrap("test");
assert!(error.to_string().contains("test"));

let error = TypeError::wrap("test");
assert!(error.to_string().contains("test"));
}
}
11 changes: 11 additions & 0 deletions src/errors/server_error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use super::RRDBError;

#[derive(Debug)]
pub struct ServerError {
pub message: String,
Expand All @@ -23,6 +25,15 @@ impl ServerError {
}
}

impl ServerError {
pub fn wrap<T: ToString>(message: T) -> RRDBError {
RRDBError::ServerError(Self {
message: message.to_string(),
backtrace: std::backtrace::Backtrace::capture(),
})
}
}

impl std::error::Error for ServerError {}

impl std::fmt::Display for ServerError {
Expand Down

0 comments on commit 4b32768

Please sign in to comment.