#![cfg(any(feature = "sqlite", feature = "postgresql", feature = "mysql"))]
mod _test_common;
define_test_user_simple!(ValidateTestUserSuccess, "validate_table_success_users_1");
define_test_user_simple!(
ValidateTestUserNotExists,
"validate_table_notexists_users_1"
);
define_test_user_simple!(
ValidateTestUserNoValidation,
"validate_table_novalidation_users_1"
);
#[cfg(any(feature = "sqlite", feature = "postgresql", feature = "mysql"))]
mod validate_table_tests {
use super::*;
use _test_common::{DbConfig, create_db_connection};
async fn test_validate_table_success_impl(
config: &DbConfig,
) -> Result<(), Box<dyn std::error::Error>> {
let db = create_db_connection(config).await?;
db.drop_table::<ValidateTestUserSuccess>()
.execute()
.await
.ok();
db.create_table::<ValidateTestUserSuccess>()
.execute()
.await?;
db.validate_table::<ValidateTestUserSuccess>().await?;
println!("validate_table succeeded for existing table");
db.drop_table::<ValidateTestUserSuccess>().execute().await?;
Ok(())
}
async fn test_validate_table_not_exists_impl(
config: &DbConfig,
) -> Result<(), Box<dyn std::error::Error>> {
let db = create_db_connection(config).await?;
db.drop_table::<ValidateTestUserNotExists>()
.execute()
.await
.ok();
let result = db.validate_table::<ValidateTestUserNotExists>().await;
assert!(
result.is_err(),
"validate_table should fail for non-existent table"
);
println!("Correctly detected non-existent table: {:?}", result.err());
Ok(())
}
async fn test_create_table_without_validation_impl(
config: &DbConfig,
) -> Result<(), Box<dyn std::error::Error>> {
let db = create_db_connection(config).await?;
db.drop_table::<ValidateTestUserNoValidation>()
.execute()
.await?;
db.create_table::<ValidateTestUserNoValidation>()
.execute()
.await?;
println!("create_table succeeded without validation");
db.drop_table::<ValidateTestUserNoValidation>()
.execute()
.await?;
Ok(())
}
test_on_all_dbs_result!(test_validate_table_success_impl);
test_on_all_dbs_result!(test_validate_table_not_exists_impl);
test_on_all_dbs_result!(test_create_table_without_validation_impl);
}