use crate::base_types::{
TgqeCoordinate, TgqeCtx, TgqeErrorInfo,
TgqePosition, TgqeSpan,
};
use crate::channel::sqlite::SQLite;
use crate::enums::TgqeLevelFilter;
fn sample_ctx() -> TgqeCtx {
let coord = TgqeCoordinate::new(
"test.rs", 1, 0, 0,
);
let span = TgqeSpan::new(
coord.clone(),
coord.clone(),
);
TgqeCtx::new(
TgqePosition::new(coord, span),
TgqeErrorInfo::new(
"winnow::error::ParseError",
"expected digit",
"found x",
TgqeLevelFilter::Error,
),
"hints",
"labels",
"winnow",
0,
)
}
#[tokio::test]
async fn save_and_batch_save_roundtrip() {
let db_path =
std::env::temp_dir().join(format!(
"tgqe_test_{}.db",
std::time::SystemTime::now()
.duration_since(
std::time::UNIX_EPOCH,
)
.unwrap()
.as_nanos()
));
let mut db = SQLite {
pool: None,
db_path: db_path.clone(),
};
db.save(&sample_ctx()).await.unwrap();
db.batch_save(&[
sample_ctx(),
sample_ctx(),
])
.await
.unwrap();
let pool = db.pool.as_ref().unwrap();
let count: i64 = sqlx::query_scalar(
"SELECT COUNT(*) FROM tgqe_errors",
)
.fetch_one(pool)
.await
.unwrap();
assert_eq!(count, 3);
let _ = std::fs::remove_file(&db_path);
}