use faucet_source_sqlite::{SqliteSource, SqliteSourceConfig};
use sqlx::sqlite::SqlitePoolOptions;
use tempfile::TempDir;
async fn seed(rows: usize) -> (TempDir, String) {
let dir = TempDir::new().expect("tempdir");
let url = format!("sqlite://{}?mode=rwc", dir.path().join("t.db").display());
let pool = SqlitePoolOptions::new()
.max_connections(1)
.connect(&url)
.await
.expect("connect");
sqlx::query("CREATE TABLE t (id INTEGER PRIMARY KEY, name TEXT)")
.execute(&pool)
.await
.expect("create");
for i in 0..rows {
sqlx::query("INSERT INTO t (id, name) VALUES (?, ?)")
.bind(i as i64)
.bind(format!("row-{i}"))
.execute(&pool)
.await
.expect("insert");
}
pool.close().await;
(dir, url)
}
#[tokio::test]
async fn conformance_config_schema_valid() {
let (_dir, url) = seed(1).await;
let source = SqliteSource::new(SqliteSourceConfig::new(url, "SELECT * FROM t"))
.await
.expect("source");
faucet_conformance::assert_config_schema_valid(&source);
}
#[tokio::test]
async fn conformance_bounded_memory() {
let total = 500;
let batch = 100;
let (_dir, url) = seed(total).await;
let source = SqliteSource::new(
SqliteSourceConfig::new(url, "SELECT id, name FROM t ORDER BY id").with_batch_size(batch),
)
.await
.expect("source");
faucet_conformance::assert_bounded_memory(&source, batch, total).await;
}
#[tokio::test]
async fn conformance_errors_not_panics() {
let (_dir, url) = seed(1).await;
let source = SqliteSource::new(SqliteSourceConfig::new(url, "SELECT * FROM missing_table"))
.await
.expect("source builds; the query only fails at read time");
faucet_conformance::assert_errors_not_panics(&source).await;
}