use burncloud_database_client::*;
use burncloud_database_core::*;
#[derive(serde::Serialize, serde::Deserialize, Debug)]
struct User {
id: String,
name: String,
email: String,
}
#[tokio::test]
async fn test_database_factory() {
let config = DatabaseConfig {
database_type: DatabaseType::Postgres,
host: "localhost".to_string(),
port: 5432,
database: "test_db".to_string(),
username: "test_user".to_string(),
password: "test_pass".to_string(),
pool_size: Some(10),
timeout: Some(5000),
ssl: Some(false),
};
let connection = DatabaseClientFactory::create_connection(&config);
assert!(connection.is_ok());
let query_executor = DatabaseClientFactory::create_query_executor(&config);
assert!(query_executor.is_ok());
}
#[tokio::test]
async fn test_database_pool() {
let config = DatabaseConfig {
database_type: DatabaseType::Postgres,
host: "localhost".to_string(),
port: 5432,
database: "test_db".to_string(),
username: "test_user".to_string(),
password: "test_pass".to_string(),
pool_size: Some(5),
timeout: Some(5000),
ssl: Some(false),
};
let pool = DatabasePool::new(config, 5);
assert_eq!(pool.get_pool_size().await, 0);
}
#[tokio::test]
async fn test_repository() {
let config = DatabaseConfig {
database_type: DatabaseType::Postgres,
host: "localhost".to_string(),
port: 5432,
database: "test_db".to_string(),
username: "test_user".to_string(),
password: "test_pass".to_string(),
pool_size: Some(5),
timeout: Some(5000),
ssl: Some(false),
};
let query_executor = DatabaseClientFactory::create_query_executor(&config).unwrap();
let repository: BaseRepository<User> = BaseRepository::new(
query_executor,
"users".to_string(),
);
assert_eq!(repository.get_table_name(), "users");
}
#[test]
fn test_query_context() {
let context = QueryContext::default();
assert!(context.request_id.is_some());
assert!(context.user_id.is_none());
assert!(!context.metadata.is_empty() == false);
}
#[test]
fn test_query_options() {
let options = QueryOptions::default();
assert!(options.limit.is_none());
assert!(options.offset.is_none());
assert!(options.order_by.is_none());
assert!(options.order_direction.is_none());
}
#[test]
fn test_database_config() {
let config = DatabaseConfig {
database_type: DatabaseType::Postgres,
host: "localhost".to_string(),
port: 5432,
database: "test_db".to_string(),
username: "test_user".to_string(),
password: "test_pass".to_string(),
pool_size: Some(10),
timeout: Some(5000),
ssl: Some(false),
};
assert_eq!(config.host, "localhost");
assert_eq!(config.port, 5432);
assert_eq!(config.pool_size, Some(10));
}