#![cfg(feature = "sqlite")]
use std::time::Duration;
use autumn_web::config::DatabaseConfig;
use autumn_web::db::{PoolError, create_pool};
#[test]
fn create_pool_rejects_configured_statement_timeout() {
let config = DatabaseConfig {
url: Some("sqlite::memory:".to_string()),
statement_timeout: Some(Duration::from_secs(30)),
..Default::default()
};
let Err(err) = create_pool(&config) else {
panic!("create_pool must fail-closed when statement_timeout is set under sqlite");
};
assert!(
matches!(err, PoolError::UnsupportedBackend(_)),
"expected UnsupportedBackend, got: {err:?}"
);
let msg = err.to_string();
assert!(
msg.contains("database.statement_timeout"),
"error must name the config key: {msg}"
);
assert!(
msg.contains("SQLite"),
"error must mention the SQLite backend: {msg}"
);
assert!(
msg.contains("30000ms"),
"error should report the configured timeout in ms: {msg}"
);
}
#[test]
fn create_topology_rejects_configured_statement_timeout() {
let config = DatabaseConfig {
url: Some("sqlite::memory:".to_string()),
statement_timeout: Some(Duration::from_millis(1500)),
..Default::default()
};
let Err(err) = autumn_web::db::create_topology(&config) else {
panic!("create_topology must fail-closed when statement_timeout is set under sqlite");
};
assert!(
matches!(err, PoolError::UnsupportedBackend(_)),
"expected UnsupportedBackend, got: {err:?}"
);
assert!(
err.to_string().contains("database.statement_timeout"),
"topology error must name the config key: {err}"
);
}
#[test]
fn create_pool_without_statement_timeout_succeeds() {
let config = DatabaseConfig {
url: Some("sqlite::memory:".to_string()),
statement_timeout: None,
..Default::default()
};
let pool = create_pool(&config)
.expect("sqlite pool must build cleanly with no statement_timeout")
.expect("a url is configured");
drop(pool);
}
#[test]
fn create_pool_with_zero_statement_timeout_succeeds() {
let config = DatabaseConfig {
url: Some("sqlite::memory:".to_string()),
statement_timeout: Some(Duration::from_secs(0)),
..Default::default()
};
let pool = create_pool(&config)
.expect("a zero statement_timeout means disabled and must build cleanly")
.expect("a url is configured");
drop(pool);
}