use prax_orm::schema::PraxConfig;
#[test]
fn test_config_minimal() {
let config_str = r#"
[database]
url = "postgresql://localhost/test"
"#;
let config: PraxConfig = toml::from_str(config_str).expect("Failed to parse config");
assert!(config.database.url.is_some());
}
#[test]
fn test_config_full() {
let config_str = r#"
[database]
provider = "postgresql"
url = "postgresql://user:pass@localhost:5432/mydb"
[database.pool]
min_connections = 2
max_connections = 20
connect_timeout = "30s"
idle_timeout = "10m"
max_lifetime = "30m"
[schema]
path = "prax/schema.prax"
[generator.client]
output = "./src/generated"
async_client = true
tracing = true
[migrations]
directory = "./prax/migrations"
auto_migrate = false
table_name = "_prax_migrations"
[seed]
script = "./seed.rs"
auto_seed = false
[debug]
log_queries = false
pretty_sql = true
slow_query_threshold = 1000
"#;
let config: PraxConfig = toml::from_str(config_str).expect("Failed to parse config");
assert!(config.database.url.is_some());
assert_eq!(config.database.pool.max_connections, 20);
}
#[test]
fn test_config_env_vars() {
let config_str = r#"
[database]
url = "${DATABASE_URL}"
"#;
let config: PraxConfig = toml::from_str(config_str).expect("Failed to parse config");
assert!(config.database.url.is_some());
}
#[test]
fn test_config_schema_path() {
let config_str = r#"
[database]
url = "postgresql://localhost/test"
[schema]
path = "custom/path/schema.prax"
"#;
let config: PraxConfig = toml::from_str(config_str).expect("Failed to parse config");
assert_eq!(config.schema.path, "custom/path/schema.prax");
}
#[test]
fn test_config_seed() {
let config_str = r#"
[database]
url = "postgresql://localhost/test"
[seed]
script = "./seed.ts"
auto_seed = true
"#;
let config: PraxConfig = toml::from_str(config_str).expect("Failed to parse config");
assert_eq!(config.seed.script, Some("./seed.ts".to_string()));
assert!(config.seed.auto_seed);
}
#[test]
fn test_config_debug() {
let config_str = r#"
[database]
url = "postgresql://localhost/test"
[debug]
log_queries = true
pretty_sql = true
slow_query_threshold = 500
"#;
let config: PraxConfig = toml::from_str(config_str).expect("Failed to parse config");
assert!(config.debug.log_queries);
assert!(config.debug.pretty_sql);
assert_eq!(config.debug.slow_query_threshold, 500);
}
#[test]
fn test_config_pool_timeouts() {
let config_str = r#"
[database]
url = "postgresql://localhost/test"
[database.pool]
connect_timeout = "30s"
idle_timeout = "10m"
max_lifetime = "1h"
"#;
let config: PraxConfig = toml::from_str(config_str).expect("Failed to parse config");
assert_eq!(config.database.pool.connect_timeout, "30s");
}
#[test]
fn test_config_migrations() {
let config_str = r#"
[database]
url = "postgresql://localhost/test"
[migrations]
directory = "./prax/migrations"
auto_migrate = false
table_name = "_custom_migrations"
"#;
let config: PraxConfig = toml::from_str(config_str).expect("Failed to parse config");
assert_eq!(config.migrations.directory, "./prax/migrations");
assert!(!config.migrations.auto_migrate);
assert_eq!(config.migrations.table_name, "_custom_migrations");
}
#[test]
fn test_config_empty_sections() {
let config_str = r#"
[database]
url = "postgresql://localhost/test"
[database.pool]
"#;
let config: PraxConfig = toml::from_str(config_str).expect("Failed to parse config");
assert!(config.database.url.is_some());
}
#[test]
fn test_config_generator() {
let config_str = r#"
[database]
url = "postgresql://localhost/test"
[generator.client]
output = "./src/generated/client"
async_client = true
"#;
let config: PraxConfig = toml::from_str(config_str).expect("Failed to parse config");
assert_eq!(config.generator.client.output, "./src/generated/client");
}