use duckdb::Connection;
use faucet_source_duckdb::{DuckdbSource, DuckdbSourceConfig};
use tempfile::TempDir;
fn seed(rows: usize) -> (TempDir, String) {
let dir = TempDir::new().expect("tempdir");
let path = dir.path().join("t.duckdb");
let path_str = path.to_string_lossy().into_owned();
{
let conn = Connection::open(&path).expect("open");
conn.execute_batch("CREATE TABLE t (id INTEGER, name TEXT)")
.expect("create");
conn.execute_batch(&format!(
"INSERT INTO t SELECT i AS id, 'row-' || i AS name FROM range(0, {rows}) t(i)"
))
.expect("insert");
} (dir, path_str)
}
#[tokio::test]
async fn conformance_config_schema_valid() {
let (_dir, path) = seed(1);
let source = DuckdbSource::new(DuckdbSourceConfig::new(path, "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, path) = seed(total);
let source = DuckdbSource::new(
DuckdbSourceConfig::new(path, "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, path) = seed(1);
let source = DuckdbSource::new(DuckdbSourceConfig::new(path, "SELECT * FROM missing_table"))
.await
.expect("source builds; the query only fails at read time");
faucet_conformance::assert_errors_not_panics(&source).await;
}