mirror of
https://github.com/fluencelabs/sqlite-wasm-connector
synced 2025-03-14 22:10:49 +00:00
improve tests
This commit is contained in:
parent
e4da5c0d4b
commit
e054b689ad
@ -4,7 +4,7 @@ orbs:
|
|||||||
docker: circleci/docker@1.5.0
|
docker: circleci/docker@1.5.0
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Build and test Rust service:
|
sqlite_connector_rust_tests:
|
||||||
docker:
|
docker:
|
||||||
- image: circleci/rust:latest
|
- image: circleci/rust:latest
|
||||||
resource_class: xlarge
|
resource_class: xlarge
|
||||||
@ -12,24 +12,31 @@ jobs:
|
|||||||
RUST_BACKTRACE: full
|
RUST_BACKTRACE: full
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- run: |
|
|
||||||
sudo bash .github/download_marine.sh
|
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
keys:
|
keys:
|
||||||
- connector-test00-{{ checksum "Cargo.lock" }}
|
- sqlite-connector01-{{ checksum "Cargo.lock" }}
|
||||||
- run: |
|
- run: |
|
||||||
|
rustup toolchain install nightly-2021-05-21
|
||||||
|
rustup default nightly-2021-05-21
|
||||||
|
rustup override set nightly-2021-05-21
|
||||||
|
|
||||||
|
rustup component add rustfmt --toolchain nightly-2021-05-21
|
||||||
|
rustup component add clippy --toolchain nightly-2021-05-21
|
||||||
rustup target add wasm32-wasi
|
rustup target add wasm32-wasi
|
||||||
- run: ./build.sh
|
|
||||||
- run: |
|
cargo fmt --all -- --check --color always
|
||||||
cargo test --no-fail-fast --release --all-features
|
cargo check -v --all-features
|
||||||
|
|
||||||
|
./build.sh
|
||||||
|
cargo test --release -v --all-features
|
||||||
- save_cache:
|
- save_cache:
|
||||||
paths:
|
paths:
|
||||||
- ~/.cargo
|
- ~/.cargo
|
||||||
- ~/.rustup
|
- ~/.rustup
|
||||||
key: connector-test00-{{ checksum "Cargo.lock" }}
|
key: sqlite-connector01-{{ checksum "Cargo.lock" }}
|
||||||
|
|
||||||
workflows:
|
workflows:
|
||||||
version: 2
|
version: 2.1
|
||||||
CircleCI:
|
marine:
|
||||||
jobs:
|
jobs:
|
||||||
- Build and test Rust service
|
- sqlite_connector_rust_tests
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,7 @@
|
|||||||
.idea/*
|
.idea/*
|
||||||
|
|
||||||
|
/artifacts
|
||||||
|
.repl_history
|
||||||
*.sqlite3
|
*.sqlite3
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
target
|
target
|
||||||
|
@ -393,7 +393,7 @@
|
|||||||
call-core 29
|
call-core 29
|
||||||
call-core 3
|
call-core 3
|
||||||
call-core 2
|
call-core 2
|
||||||
byte_array.lift_memory
|
string.lift_memory
|
||||||
call-core 1)
|
call-core 1)
|
||||||
(@interface func (type 59)
|
(@interface func (type 59)
|
||||||
arg.get 0
|
arg.get 0
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
//!
|
//!
|
||||||
//! Open a connection, create a table, and insert some rows:
|
//! Open a connection, create a table, and insert some rows:
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```ignore
|
||||||
//! let connection = sqlite::open(":memory:").unwrap();
|
//! let connection = sqlite::open(":memory:").unwrap();
|
||||||
//!
|
//!
|
||||||
//! connection
|
//! connection
|
||||||
@ -20,7 +20,7 @@
|
|||||||
//!
|
//!
|
||||||
//! Select some rows and process them one by one as plain text:
|
//! Select some rows and process them one by one as plain text:
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```ignore
|
||||||
//! # let connection = sqlite::open(":memory:").unwrap();
|
//! # let connection = sqlite::open(":memory:").unwrap();
|
||||||
//! # connection
|
//! # connection
|
||||||
//! # .execute(
|
//! # .execute(
|
||||||
@ -44,7 +44,7 @@
|
|||||||
//! The same query using a prepared statement, which is much more efficient than
|
//! The same query using a prepared statement, which is much more efficient than
|
||||||
//! the previous technique:
|
//! the previous technique:
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```ignore
|
||||||
//! use sqlite::State;
|
//! use sqlite::State;
|
||||||
//! # let connection = sqlite::open(":memory:").unwrap();
|
//! # let connection = sqlite::open(":memory:").unwrap();
|
||||||
//! # connection
|
//! # connection
|
||||||
@ -72,7 +72,7 @@
|
|||||||
//! The same query using a cursor, which is a wrapper around a prepared
|
//! The same query using a cursor, which is a wrapper around a prepared
|
||||||
//! statement providing the concept of row and featuring all-at-once binding:
|
//! statement providing the concept of row and featuring all-at-once binding:
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```ignore
|
||||||
//! use sqlite::Value;
|
//! use sqlite::Value;
|
||||||
//! # let connection = sqlite::open(":memory:").unwrap();
|
//! # let connection = sqlite::open(":memory:").unwrap();
|
||||||
//! # connection
|
//! # connection
|
||||||
|
61
src/test.rs
61
src/test.rs
@ -1,5 +1,6 @@
|
|||||||
use marine_rs_sdk::marine;
|
use marine_rs_sdk::marine;
|
||||||
use marine_sqlite_connector::State;
|
use marine_sqlite_connector::State;
|
||||||
|
use marine_sqlite_connector::Value;
|
||||||
|
|
||||||
pub fn main() {}
|
pub fn main() {}
|
||||||
|
|
||||||
@ -7,31 +8,6 @@ pub fn main() {}
|
|||||||
pub fn test1() {
|
pub fn test1() {
|
||||||
let connection = marine_sqlite_connector::open(":memory:").unwrap();
|
let connection = marine_sqlite_connector::open(":memory:").unwrap();
|
||||||
|
|
||||||
connection
|
|
||||||
.execute(
|
|
||||||
"
|
|
||||||
CREATE TABLE users (name TEXT, age INTEGER);
|
|
||||||
INSERT INTO users VALUES ('Alice', 42);
|
|
||||||
INSERT INTO users VALUES ('Bob', 69);
|
|
||||||
",
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
connection
|
|
||||||
.iterate("SELECT * FROM users WHERE age > 50", |pairs| {
|
|
||||||
for &(column, value) in pairs.iter() {
|
|
||||||
println!("{} = {}", column, value.unwrap());
|
|
||||||
}
|
|
||||||
true
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[marine]
|
|
||||||
pub fn test2() {
|
|
||||||
let connection = marine_sqlite_connector::open(":memory:").unwrap();
|
|
||||||
|
|
||||||
println!("connection id = {}\n", connection.as_raw());
|
|
||||||
connection
|
connection
|
||||||
.execute(
|
.execute(
|
||||||
"
|
"
|
||||||
@ -48,15 +24,13 @@ pub fn test2() {
|
|||||||
|
|
||||||
statement.bind(1, 50).unwrap();
|
statement.bind(1, 50).unwrap();
|
||||||
|
|
||||||
while let State::Row = statement.next().unwrap() {
|
assert_eq!(statement.next().unwrap(), State::Row);
|
||||||
println!("name = {}", statement.read::<String>(0).unwrap());
|
assert_eq!(statement.read::<String>(0).unwrap(), "Bob");
|
||||||
println!("age = {}", statement.read::<i64>(1).unwrap());
|
assert_eq!(statement.read::<i64>(1).unwrap(), 69);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#[marine]
|
|
||||||
pub fn test3() {
|
|
||||||
use marine_sqlite_connector::Value;
|
|
||||||
|
|
||||||
|
#[marine]
|
||||||
|
pub fn test2() {
|
||||||
let connection = marine_sqlite_connector::open(":memory:").unwrap();
|
let connection = marine_sqlite_connector::open(":memory:").unwrap();
|
||||||
|
|
||||||
connection
|
connection
|
||||||
@ -77,15 +51,13 @@ pub fn test3() {
|
|||||||
cursor.bind(&[Value::Integer(50)]).unwrap();
|
cursor.bind(&[Value::Integer(50)]).unwrap();
|
||||||
|
|
||||||
while let Some(row) = cursor.next().unwrap() {
|
while let Some(row) = cursor.next().unwrap() {
|
||||||
println!("name = {}", row[0].as_string().unwrap());
|
assert_eq!(row[0].as_string().unwrap(), "Bob");
|
||||||
println!("age = {}", row[1].as_integer().unwrap());
|
assert_eq!(row[1].as_integer().unwrap(), 69);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[marine]
|
#[marine]
|
||||||
pub fn test4() {
|
pub fn test3() {
|
||||||
use marine_sqlite_connector::Value;
|
|
||||||
|
|
||||||
let connection = marine_sqlite_connector::open(":memory:").unwrap();
|
let connection = marine_sqlite_connector::open(":memory:").unwrap();
|
||||||
|
|
||||||
connection
|
connection
|
||||||
@ -103,13 +75,12 @@ pub fn test4() {
|
|||||||
cursor.bind(1, &Value::Integer(50)).unwrap();
|
cursor.bind(1, &Value::Integer(50)).unwrap();
|
||||||
cursor.bind(2, &Value::Binary(vec![1, 2, 3])).unwrap();
|
cursor.bind(2, &Value::Binary(vec![1, 2, 3])).unwrap();
|
||||||
|
|
||||||
cursor.next().unwrap();
|
// check that blob is not null
|
||||||
|
assert!(cursor.next().is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[marine]
|
#[marine]
|
||||||
pub fn test5() {
|
pub fn test4() {
|
||||||
use marine_sqlite_connector::Value;
|
|
||||||
|
|
||||||
let connection = marine_sqlite_connector::open(":memory:").unwrap();
|
let connection = marine_sqlite_connector::open(":memory:").unwrap();
|
||||||
|
|
||||||
connection
|
connection
|
||||||
@ -137,12 +108,6 @@ pub fn test5() {
|
|||||||
cursor.bind(&[Value::Integer(50)]).unwrap();
|
cursor.bind(&[Value::Integer(50)]).unwrap();
|
||||||
|
|
||||||
while let Some(row) = cursor.next().unwrap() {
|
while let Some(row) = cursor.next().unwrap() {
|
||||||
if vec![1, 2, 3] != row[0].as_binary().unwrap().to_vec() {
|
assert_eq!(row[0].as_binary().unwrap().to_vec(), vec![1, 2, 3]);
|
||||||
println!(
|
|
||||||
"expected: {:?}, actual: {:?}",
|
|
||||||
vec![1, 2, 3],
|
|
||||||
row[0].as_binary().unwrap()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,4 @@ mod tests {
|
|||||||
fn test4(test: marine_test_env::test::ModuleInterface) {
|
fn test4(test: marine_test_env::test::ModuleInterface) {
|
||||||
test.test4()
|
test.test4()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[marine_test(config_path = "../Config.toml", modules_dir = "../artifacts/")]
|
|
||||||
fn test5(test: marine_test_env::test::ModuleInterface) {
|
|
||||||
test.test5()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user