mirror of
https://github.com/fluencelabs/sqlite-wasm-connector
synced 2025-03-14 14:00: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
|
||||
|
||||
jobs:
|
||||
Build and test Rust service:
|
||||
sqlite_connector_rust_tests:
|
||||
docker:
|
||||
- image: circleci/rust:latest
|
||||
resource_class: xlarge
|
||||
@ -12,24 +12,31 @@ jobs:
|
||||
RUST_BACKTRACE: full
|
||||
steps:
|
||||
- checkout
|
||||
- run: |
|
||||
sudo bash .github/download_marine.sh
|
||||
- restore_cache:
|
||||
keys:
|
||||
- connector-test00-{{ checksum "Cargo.lock" }}
|
||||
- sqlite-connector01-{{ checksum "Cargo.lock" }}
|
||||
- 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
|
||||
- run: ./build.sh
|
||||
- run: |
|
||||
cargo test --no-fail-fast --release --all-features
|
||||
|
||||
cargo fmt --all -- --check --color always
|
||||
cargo check -v --all-features
|
||||
|
||||
./build.sh
|
||||
cargo test --release -v --all-features
|
||||
- save_cache:
|
||||
paths:
|
||||
- ~/.cargo
|
||||
- ~/.rustup
|
||||
key: connector-test00-{{ checksum "Cargo.lock" }}
|
||||
key: sqlite-connector01-{{ checksum "Cargo.lock" }}
|
||||
|
||||
workflows:
|
||||
version: 2
|
||||
CircleCI:
|
||||
version: 2.1
|
||||
marine:
|
||||
jobs:
|
||||
- Build and test Rust service
|
||||
- sqlite_connector_rust_tests
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,7 @@
|
||||
.idea/*
|
||||
|
||||
/artifacts
|
||||
.repl_history
|
||||
*.sqlite3
|
||||
Cargo.lock
|
||||
target
|
||||
|
@ -393,7 +393,7 @@
|
||||
call-core 29
|
||||
call-core 3
|
||||
call-core 2
|
||||
byte_array.lift_memory
|
||||
string.lift_memory
|
||||
call-core 1)
|
||||
(@interface func (type 59)
|
||||
arg.get 0
|
||||
|
@ -4,7 +4,7 @@
|
||||
//!
|
||||
//! Open a connection, create a table, and insert some rows:
|
||||
//!
|
||||
//! ```
|
||||
//! ```ignore
|
||||
//! let connection = sqlite::open(":memory:").unwrap();
|
||||
//!
|
||||
//! connection
|
||||
@ -20,7 +20,7 @@
|
||||
//!
|
||||
//! Select some rows and process them one by one as plain text:
|
||||
//!
|
||||
//! ```
|
||||
//! ```ignore
|
||||
//! # let connection = sqlite::open(":memory:").unwrap();
|
||||
//! # connection
|
||||
//! # .execute(
|
||||
@ -44,7 +44,7 @@
|
||||
//! The same query using a prepared statement, which is much more efficient than
|
||||
//! the previous technique:
|
||||
//!
|
||||
//! ```
|
||||
//! ```ignore
|
||||
//! use sqlite::State;
|
||||
//! # let connection = sqlite::open(":memory:").unwrap();
|
||||
//! # connection
|
||||
@ -72,7 +72,7 @@
|
||||
//! 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:
|
||||
//!
|
||||
//! ```
|
||||
//! ```ignore
|
||||
//! use sqlite::Value;
|
||||
//! # let connection = sqlite::open(":memory:").unwrap();
|
||||
//! # connection
|
||||
|
61
src/test.rs
61
src/test.rs
@ -1,5 +1,6 @@
|
||||
use marine_rs_sdk::marine;
|
||||
use marine_sqlite_connector::State;
|
||||
use marine_sqlite_connector::Value;
|
||||
|
||||
pub fn main() {}
|
||||
|
||||
@ -7,31 +8,6 @@ pub fn main() {}
|
||||
pub fn test1() {
|
||||
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
|
||||
.execute(
|
||||
"
|
||||
@ -48,15 +24,13 @@ pub fn test2() {
|
||||
|
||||
statement.bind(1, 50).unwrap();
|
||||
|
||||
while let State::Row = statement.next().unwrap() {
|
||||
println!("name = {}", statement.read::<String>(0).unwrap());
|
||||
println!("age = {}", statement.read::<i64>(1).unwrap());
|
||||
}
|
||||
assert_eq!(statement.next().unwrap(), State::Row);
|
||||
assert_eq!(statement.read::<String>(0).unwrap(), "Bob");
|
||||
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();
|
||||
|
||||
connection
|
||||
@ -77,15 +51,13 @@ pub fn test3() {
|
||||
cursor.bind(&[Value::Integer(50)]).unwrap();
|
||||
|
||||
while let Some(row) = cursor.next().unwrap() {
|
||||
println!("name = {}", row[0].as_string().unwrap());
|
||||
println!("age = {}", row[1].as_integer().unwrap());
|
||||
assert_eq!(row[0].as_string().unwrap(), "Bob");
|
||||
assert_eq!(row[1].as_integer().unwrap(), 69);
|
||||
}
|
||||
}
|
||||
|
||||
#[marine]
|
||||
pub fn test4() {
|
||||
use marine_sqlite_connector::Value;
|
||||
|
||||
pub fn test3() {
|
||||
let connection = marine_sqlite_connector::open(":memory:").unwrap();
|
||||
|
||||
connection
|
||||
@ -103,13 +75,12 @@ pub fn test4() {
|
||||
cursor.bind(1, &Value::Integer(50)).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]
|
||||
pub fn test5() {
|
||||
use marine_sqlite_connector::Value;
|
||||
|
||||
pub fn test4() {
|
||||
let connection = marine_sqlite_connector::open(":memory:").unwrap();
|
||||
|
||||
connection
|
||||
@ -137,12 +108,6 @@ pub fn test5() {
|
||||
cursor.bind(&[Value::Integer(50)]).unwrap();
|
||||
|
||||
while let Some(row) = cursor.next().unwrap() {
|
||||
if vec![1, 2, 3] != row[0].as_binary().unwrap().to_vec() {
|
||||
println!(
|
||||
"expected: {:?}, actual: {:?}",
|
||||
vec![1, 2, 3],
|
||||
row[0].as_binary().unwrap()
|
||||
);
|
||||
}
|
||||
assert_eq!(row[0].as_binary().unwrap().to_vec(), vec![1, 2, 3]);
|
||||
}
|
||||
}
|
||||
|
@ -38,9 +38,4 @@ mod tests {
|
||||
fn test4(test: marine_test_env::test::ModuleInterface) {
|
||||
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