From e054b689ad73a581c1ad77e948933d4a30035b7c Mon Sep 17 00:00:00 2001 From: vms Date: Fri, 3 Sep 2021 19:45:23 +0300 Subject: [PATCH] improve tests --- .circleci/config.yml | 29 +++++++++++++-------- .gitignore | 2 ++ sqlite3.wit | 2 +- src/lib.rs | 8 +++--- src/test.rs | 61 ++++++++++---------------------------------- tests/tests.rs | 5 ---- 6 files changed, 38 insertions(+), 69 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d1b74e7..05226af 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 \ No newline at end of file diff --git a/.gitignore b/.gitignore index e0fcc69..9af404a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ .idea/* +/artifacts +.repl_history *.sqlite3 Cargo.lock target diff --git a/sqlite3.wit b/sqlite3.wit index 936a403..8b624af 100644 --- a/sqlite3.wit +++ b/sqlite3.wit @@ -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 diff --git a/src/lib.rs b/src/lib.rs index 1fee0e5..6acef65 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 diff --git a/src/test.rs b/src/test.rs index 8d88717..e3a0ca4 100644 --- a/src/test.rs +++ b/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::(0).unwrap()); - println!("age = {}", statement.read::(1).unwrap()); - } + assert_eq!(statement.next().unwrap(), State::Row); + assert_eq!(statement.read::(0).unwrap(), "Bob"); + assert_eq!(statement.read::(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]); } } diff --git a/tests/tests.rs b/tests/tests.rs index 2440511..b106b2f 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -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() - } }