mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-09 11:14:20 +01:00
setup basic playground for fuzzing against sqlite
This commit is contained in:
@@ -5,7 +5,7 @@ authors.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
description = "Integration tests"
|
||||
description = "Integration & fuzz tests"
|
||||
|
||||
[lib]
|
||||
path = "lib.rs"
|
||||
@@ -14,6 +14,10 @@ path = "lib.rs"
|
||||
name = "integration_tests"
|
||||
path = "integration/mod.rs"
|
||||
|
||||
[[test]]
|
||||
name = "fuzz_tests"
|
||||
path = "fuzz/mod.rs"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.75"
|
||||
clap = { version = "4.5", features = ["derive"] }
|
||||
|
||||
67
tests/fuzz/mod.rs
Normal file
67
tests/fuzz/mod.rs
Normal file
@@ -0,0 +1,67 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{rc::Rc, sync::Arc};
|
||||
|
||||
use limbo_core::Database;
|
||||
use rusqlite::params;
|
||||
|
||||
fn sqlite_exec_row(conn: &rusqlite::Connection, query: &str) -> Vec<rusqlite::types::Value> {
|
||||
let mut stmt = conn.prepare(&query).unwrap();
|
||||
let mut rows = stmt.query(params![]).unwrap();
|
||||
let mut columns = Vec::new();
|
||||
let row = rows.next().unwrap().unwrap();
|
||||
for i in 0.. {
|
||||
let column: rusqlite::types::Value = match row.get(i) {
|
||||
Ok(column) => column,
|
||||
Err(rusqlite::Error::InvalidColumnIndex(_)) => break,
|
||||
Err(err) => panic!("unexpected rusqlite error: {}", err),
|
||||
};
|
||||
columns.push(column);
|
||||
}
|
||||
assert!(rows.next().unwrap().is_none());
|
||||
|
||||
columns
|
||||
}
|
||||
|
||||
fn limbo_exec_row(
|
||||
conn: &Rc<limbo_core::Connection>,
|
||||
query: &str,
|
||||
) -> Vec<rusqlite::types::Value> {
|
||||
let mut stmt = conn.prepare(query).unwrap();
|
||||
let result = stmt.step().unwrap();
|
||||
let row = loop {
|
||||
match result {
|
||||
limbo_core::StepResult::Row(row) => break row,
|
||||
limbo_core::StepResult::IO => continue,
|
||||
r => panic!("unexpected result {:?}: expecting single row", r),
|
||||
}
|
||||
};
|
||||
row.values
|
||||
.iter()
|
||||
.map(|x| match x {
|
||||
limbo_core::Value::Null => rusqlite::types::Value::Null,
|
||||
limbo_core::Value::Integer(x) => rusqlite::types::Value::Integer(*x),
|
||||
limbo_core::Value::Float(x) => rusqlite::types::Value::Real(*x),
|
||||
limbo_core::Value::Text(x) => rusqlite::types::Value::Text((*x).clone()),
|
||||
limbo_core::Value::Blob(x) => rusqlite::types::Value::Blob((*x).clone()),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn kek() {
|
||||
let io = Arc::new(limbo_core::PlatformIO::new().unwrap());
|
||||
let limbo_db = Database::open_file(io, ":memory:").unwrap();
|
||||
let limbo_conn = limbo_db.connect();
|
||||
let sqlite_conn = rusqlite::Connection::open_in_memory().unwrap();
|
||||
|
||||
println!(
|
||||
"column: {:?}",
|
||||
sqlite_exec_row(&sqlite_conn, "SELECT 1 = 1.0")
|
||||
);
|
||||
println!(
|
||||
"column: {:?}",
|
||||
limbo_exec_row(&limbo_conn, "SELECT 1 = 1.0")
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user