Give up and fix tests
This commit is contained in:
parent
0ce0f49551
commit
85533a3bb3
@ -91,17 +91,6 @@ pub fn impl_col_from_str(ident: &Ident, data: &Data) -> syn::Result<TokenStream>
|
||||
)
|
||||
});
|
||||
|
||||
let entity_name = data_enum
|
||||
.variants
|
||||
.first()
|
||||
.map(|column| {
|
||||
let column_iden = column.ident.clone();
|
||||
quote!(
|
||||
#ident::#column_iden.entity_name().to_string()
|
||||
)
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
Ok(quote!(
|
||||
#[automatically_derived]
|
||||
impl std::str::FromStr for #ident {
|
||||
@ -110,7 +99,7 @@ pub fn impl_col_from_str(ident: &Ident, data: &Data) -> syn::Result<TokenStream>
|
||||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
||||
match s {
|
||||
#(#columns),*,
|
||||
_ => Err(sea_orm::ColumnFromStrErr{ string: s.to_owned(), entity: #entity_name }),
|
||||
_ => Err(sea_orm::ColumnFromStrErr(s.to_owned())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -102,7 +102,9 @@ impl MockDatabaseTrait for MockDatabase {
|
||||
result: ExecResultHolder::Mock(std::mem::take(&mut self.exec_results[counter])),
|
||||
})
|
||||
} else {
|
||||
Err(DbErr::Query("`exec_results` buffer is empty.".to_owned()))
|
||||
Err(DbErr::Query(RuntimeErr::Internal(
|
||||
"`exec_results` buffer is empty.".to_owned(),
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,7 +123,9 @@ impl MockDatabaseTrait for MockDatabase {
|
||||
})
|
||||
.collect())
|
||||
} else {
|
||||
Err(DbErr::Query("`query_results` buffer is empty.".to_owned()))
|
||||
Err(DbErr::Query(RuntimeErr::Internal(
|
||||
"`query_results` buffer is empty.".to_owned(),
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,7 +180,7 @@ impl MockRow {
|
||||
where
|
||||
T: ValueType,
|
||||
{
|
||||
T::try_from(self.values.get(col).unwrap().clone()).map_err(|e| DbErr::Query(e.to_string()))
|
||||
T::try_from(self.values.get(col).unwrap().clone()).map_err(|e| DbErr::Type(e.to_string()))
|
||||
}
|
||||
|
||||
/// An iterator over the keys and values of a mock row
|
||||
|
@ -521,7 +521,7 @@ mod tests {
|
||||
));
|
||||
assert!(matches!(
|
||||
fruit::Column::from_str("does_not_exist"),
|
||||
Err(crate::ColumnFromStrErr { .. })
|
||||
Err(crate::ColumnFromStrErr(_))
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -76,10 +76,5 @@ impl Eq for DbErr {}
|
||||
|
||||
/// Error during `impl FromStr for Entity::Column`
|
||||
#[derive(Error, Debug)]
|
||||
#[error("Failed to match \"{string}\" as Column for `{entity}`")]
|
||||
pub struct ColumnFromStrErr {
|
||||
/// Source of error
|
||||
pub string: String,
|
||||
/// Entity this column belongs to
|
||||
pub entity: String,
|
||||
}
|
||||
#[error("Failed to match \"{0}\" as Column")]
|
||||
pub struct ColumnFromStrErr(pub String);
|
||||
|
@ -816,20 +816,22 @@ try_from_u64_err!(uuid::Uuid);
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::TryGetError;
|
||||
use crate::error::DbErr;
|
||||
use crate::error::*;
|
||||
|
||||
#[test]
|
||||
fn from_try_get_error() {
|
||||
// TryGetError::DbErr
|
||||
let try_get_error = TryGetError::DbErr(DbErr::Query("expected error message".to_owned()));
|
||||
let try_get_error = TryGetError::DbErr(DbErr::Query(RuntimeErr::Internal(
|
||||
"expected error message".to_owned(),
|
||||
)));
|
||||
assert_eq!(
|
||||
DbErr::from(try_get_error),
|
||||
DbErr::Query("expected error message".to_owned())
|
||||
DbErr::Query(RuntimeErr::Internal("expected error message".to_owned()))
|
||||
);
|
||||
|
||||
// TryGetError::Null
|
||||
let try_get_error = TryGetError::Null("column".to_owned());
|
||||
let expected = "error occurred while decoding column: Null".to_owned();
|
||||
assert_eq!(DbErr::from(try_get_error), DbErr::Query(expected));
|
||||
let expected = "A null value was encountered while decoding column".to_owned();
|
||||
assert_eq!(DbErr::from(try_get_error), DbErr::Type(expected));
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
pub use super::*;
|
||||
use rust_decimal_macros::dec;
|
||||
use sea_orm::DbErr;
|
||||
use sea_orm::error::*;
|
||||
#[cfg(any(
|
||||
feature = "sqlx-mysql",
|
||||
feature = "sqlx-sqlite",
|
||||
@ -32,7 +32,7 @@ pub async fn test_cake_error_sqlx(db: &DbConn) {
|
||||
|
||||
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-sqlite"))]
|
||||
match error {
|
||||
DbErr::ExecSqlX(sqlx_error) => match sqlx_error {
|
||||
DbErr::Exec(RuntimeErr::SqlxError(error)) => match error {
|
||||
Error::Database(e) => {
|
||||
#[cfg(feature = "sqlx-mysql")]
|
||||
assert_eq!(e.code().unwrap(), "23000");
|
||||
@ -45,7 +45,7 @@ pub async fn test_cake_error_sqlx(db: &DbConn) {
|
||||
}
|
||||
#[cfg(feature = "sqlx-postgres")]
|
||||
match error {
|
||||
DbErr::QuerySqlX(sqlx_error) => match sqlx_error {
|
||||
DbErr::Query(RuntimeErr::SqlxError(error)) => match error {
|
||||
Error::Database(e) => {
|
||||
assert_eq!(e.code().unwrap(), "23505");
|
||||
}
|
||||
|
@ -508,7 +508,9 @@ pub async fn transaction_nested() {
|
||||
assert_eq!(bakeries.len(), 4);
|
||||
|
||||
if true {
|
||||
Err(DbErr::Query("Force Rollback!".to_owned()))
|
||||
Err(DbErr::Query(RuntimeErr::Internal(
|
||||
"Force Rollback!".to_owned(),
|
||||
)))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
@ -633,7 +635,9 @@ pub async fn transaction_nested() {
|
||||
assert_eq!(bakeries.len(), 7);
|
||||
|
||||
if true {
|
||||
Err(DbErr::Query("Force Rollback!".to_owned()))
|
||||
Err(DbErr::Query(RuntimeErr::Internal(
|
||||
"Force Rollback!".to_owned(),
|
||||
)))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
@ -652,7 +656,9 @@ pub async fn transaction_nested() {
|
||||
assert_eq!(bakeries.len(), 6);
|
||||
|
||||
if true {
|
||||
Err(DbErr::Query("Force Rollback!".to_owned()))
|
||||
Err(DbErr::Query(RuntimeErr::Internal(
|
||||
"Force Rollback!".to_owned(),
|
||||
)))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user