mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-05 21:02:58 +00:00
refactor: try to remove unnecessary tests in error mod (#750)
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
This commit is contained in:
@@ -109,135 +109,3 @@ impl ErrorExt for Error {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
type StdResult<E> = std::result::Result<(), E>;
|
||||
|
||||
fn throw_none_option() -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_connect_failed_error() {
|
||||
fn throw_tonic_error() -> StdResult<tonic::transport::Error> {
|
||||
tonic::transport::Endpoint::new("http//http").map(|_| ())
|
||||
}
|
||||
let e = throw_tonic_error()
|
||||
.context(ConnectFailedSnafu { url: "" })
|
||||
.err()
|
||||
.unwrap();
|
||||
assert!(e.backtrace_opt().is_some());
|
||||
assert_eq!(e.status_code(), StatusCode::Internal);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_illegal_grpc_client_state_error() {
|
||||
let e = throw_none_option()
|
||||
.context(IllegalGrpcClientStateSnafu { err_msg: "" })
|
||||
.err()
|
||||
.unwrap();
|
||||
assert!(e.backtrace_opt().is_some());
|
||||
assert_eq!(e.status_code(), StatusCode::Internal);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tonic_status_error() {
|
||||
fn throw_tonic_status_error() -> StdResult<tonic::Status> {
|
||||
Err(tonic::Status::new(tonic::Code::Aborted, ""))
|
||||
}
|
||||
let e = throw_tonic_status_error()
|
||||
.context(TonicStatusSnafu)
|
||||
.err()
|
||||
.unwrap();
|
||||
assert!(e.backtrace_opt().is_some());
|
||||
assert_eq!(e.status_code(), StatusCode::Internal);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ask_leader_error() {
|
||||
let e = throw_none_option().context(AskLeaderSnafu).err().unwrap();
|
||||
assert!(e.backtrace_opt().is_some());
|
||||
assert_eq!(e.status_code(), StatusCode::Internal);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_leader_error() {
|
||||
let e = throw_none_option().context(NoLeaderSnafu).err().unwrap();
|
||||
assert!(e.backtrace_opt().is_some());
|
||||
assert_eq!(e.status_code(), StatusCode::Internal);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_create_channel_error() {
|
||||
fn throw_common_grpc_error() -> StdResult<common_grpc::Error> {
|
||||
tonic::transport::Endpoint::new("http//http")
|
||||
.map(|_| ())
|
||||
.context(common_grpc::error::CreateChannelSnafu)
|
||||
}
|
||||
let e = throw_common_grpc_error()
|
||||
.context(CreateChannelSnafu)
|
||||
.err()
|
||||
.unwrap();
|
||||
assert!(e.backtrace_opt().is_some());
|
||||
assert_eq!(e.status_code(), StatusCode::Internal);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_not_started_error() {
|
||||
let e = throw_none_option()
|
||||
.context(NotStartedSnafu { name: "" })
|
||||
.err()
|
||||
.unwrap();
|
||||
assert!(e.backtrace_opt().is_some());
|
||||
assert_eq!(e.status_code(), StatusCode::Internal);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_send_heartbeat_error() {
|
||||
let e = throw_none_option()
|
||||
.context(SendHeartbeatSnafu { err_msg: "" })
|
||||
.err()
|
||||
.unwrap();
|
||||
assert!(e.backtrace_opt().is_some());
|
||||
assert_eq!(e.status_code(), StatusCode::Internal);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_create_heartbeat_stream_error() {
|
||||
let e = throw_none_option()
|
||||
.context(CreateHeartbeatStreamSnafu)
|
||||
.err()
|
||||
.unwrap();
|
||||
|
||||
assert!(e.backtrace_opt().is_some());
|
||||
assert_eq!(e.status_code(), StatusCode::Internal);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_route_info_corruped_error() {
|
||||
let e = throw_none_option()
|
||||
.context(RouteInfoCorruptedSnafu { err_msg: "" })
|
||||
.err()
|
||||
.unwrap();
|
||||
|
||||
assert!(e.backtrace_opt().is_some());
|
||||
assert_eq!(e.status_code(), StatusCode::Unexpected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_illegal_server_state_error() {
|
||||
let e = throw_none_option()
|
||||
.context(IllegalServerStateSnafu {
|
||||
code: 1,
|
||||
err_msg: "",
|
||||
})
|
||||
.err()
|
||||
.unwrap();
|
||||
|
||||
assert!(e.backtrace_opt().is_some());
|
||||
assert_eq!(e.status_code(), StatusCode::Internal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,63 +185,3 @@ impl ErrorExt for Error {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::assert_matches::assert_matches;
|
||||
|
||||
use super::*;
|
||||
|
||||
fn throw_sp_error() -> std::result::Result<(), ParserError> {
|
||||
Err(ParserError::ParserError("parser error".to_string()))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_syntax_error() {
|
||||
let err = throw_sp_error()
|
||||
.context(SyntaxSnafu { sql: "" })
|
||||
.err()
|
||||
.unwrap();
|
||||
assert_matches!(
|
||||
err,
|
||||
Error::Syntax {
|
||||
sql: _,
|
||||
source: ParserError::ParserError { .. }
|
||||
}
|
||||
);
|
||||
assert_eq!(StatusCode::InvalidSyntax, err.status_code());
|
||||
|
||||
let err = throw_sp_error()
|
||||
.context(UnexpectedSnafu {
|
||||
sql: "",
|
||||
expected: "",
|
||||
actual: "",
|
||||
})
|
||||
.err()
|
||||
.unwrap();
|
||||
assert_eq!(StatusCode::InvalidSyntax, err.status_code());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unsupported_error() {
|
||||
let err = Error::Unsupported {
|
||||
sql: "".to_string(),
|
||||
keyword: "".to_string(),
|
||||
};
|
||||
assert_eq!(StatusCode::Unsupported, err.status_code());
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_tokenizer_error() {
|
||||
let err = Error::Tokenizer {
|
||||
sql: "".to_string(),
|
||||
source: sqlparser::tokenizer::TokenizerError {
|
||||
message: "tokenizer error".to_string(),
|
||||
col: 1,
|
||||
line: 1,
|
||||
},
|
||||
};
|
||||
|
||||
assert_eq!(StatusCode::InvalidSyntax, err.status_code());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user