feat: implement bots including tests

this starts work on #78
This commit is contained in:
Paul Makles
2023-04-22 14:25:02 +01:00
parent 56ead0f894
commit 6b10385c0d
11 changed files with 311 additions and 31 deletions

View File

@@ -99,7 +99,7 @@ pub enum ErrorType {
// ? General errors
DatabaseError {
operation: String,
with: String,
collection: String,
},
InternalError,
InvalidOperation,
@@ -119,14 +119,24 @@ pub enum ErrorType {
#[macro_export]
macro_rules! create_error {
( $error:ident ) => {
( $error:ident $( $tt:tt )? ) => {
$crate::Error {
error_type: $crate::ErrorType::$error,
error_type: $crate::ErrorType::$error $( $tt )?,
location: format!("{}:{}:{}", file!(), line!(), column!()),
}
};
}
#[macro_export]
macro_rules! create_database_error {
( $operation:expr, $collection:expr ) => {
create_error!(DatabaseError {
operation: $operation.to_string(),
collection: $collection.to_string()
})
};
}
#[cfg(test)]
mod tests {
use crate::ErrorType;
@@ -136,4 +146,10 @@ mod tests {
let error = create_error!(LabelMe);
assert!(matches!(error.error_type, ErrorType::LabelMe));
}
#[test]
fn use_macro_to_construct_complex_error() {
let error = create_error!(LabelMe);
assert!(matches!(error.error_type, ErrorType::LabelMe));
}
}