From 13c168215203c34d73bad5269b46e4a75c00f772 Mon Sep 17 00:00:00 2001 From: Avinash Sajjanshetty Date: Thu, 15 Feb 2024 22:48:17 +0530 Subject: [PATCH] Add tests for sqlite-vss extension --- .github/workflows/extensions-test.yml | 24 ++++++++++++++++++- .../test/rust_suite/src/extensions.rs | 18 ++++++++++++++ libsql-sqlite3/test/rust_suite/src/lib.rs | 2 ++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 libsql-sqlite3/test/rust_suite/src/extensions.rs diff --git a/.github/workflows/extensions-test.yml b/.github/workflows/extensions-test.yml index 813c7ec754..17e1f27a5a 100644 --- a/.github/workflows/extensions-test.yml +++ b/.github/workflows/extensions-test.yml @@ -54,4 +54,26 @@ jobs: - name: test run: | cd ext/crr/rs/core - cargo test --features=loadable_extension \ No newline at end of file + cargo test --features=loadable_extension + + extensions-tests: + runs-on: ubuntu-latest + name: Extensions Tests + + steps: + - uses: hecrj/setup-rust-action@v1 + - name: Checkout repository + uses: actions/checkout@v3 + - name: build libsql and ffi bindings + run: | + cargo xtask build-bundled + - name: download extensions + run: | + cd libsql-sqlite3/test/rust_suite + export VSS_VERSION="v0.1.2" + wget https://github.com/asg017/sqlite-vss/releases/download/$VSS_VERSION/sqlite-vss-$VSS_VERSION-loadable-linux-x86_64.tar.gz + tar -xvf sqlite-vss-$VSS_VERSION-loadable-linux-x86_64.tar.gz -C src + - name: test + run: | + cd libsql-sqlite3/test/rust_suite + cargo test \ No newline at end of file diff --git a/libsql-sqlite3/test/rust_suite/src/extensions.rs b/libsql-sqlite3/test/rust_suite/src/extensions.rs new file mode 100644 index 0000000000..02defdca2d --- /dev/null +++ b/libsql-sqlite3/test/rust_suite/src/extensions.rs @@ -0,0 +1,18 @@ +use libsql_sys::rusqlite::{Connection, params, LoadExtensionGuard}; + +#[test] +fn test_sqlite_vss() { + let conn = Connection::open_in_memory().unwrap(); + unsafe { + let _guard = LoadExtensionGuard::new(&conn).unwrap(); + conn.load_extension("src/vector0", None).unwrap(); + conn.load_extension("src/vss0", None).unwrap(); + } + conn.execute("CREATE VIRTUAL TABLE IF NOT EXISTS vss_demo USING vss0(a(2))", ()) + .unwrap(); + conn.execute("INSERT INTO vss_demo(rowid, a) VALUES (1, '[1.0, 2.0]'), (2, '[2.0, 2.0]'), (3, '[3.0, 2.0]')", ()).unwrap(); + conn.execute( + "SELECT rowid, distance FROM vss_demo WHERE vss_search(?, ?) LIMIT 3", + params![1.0, 2.0], + ).unwrap(); +} \ No newline at end of file diff --git a/libsql-sqlite3/test/rust_suite/src/lib.rs b/libsql-sqlite3/test/rust_suite/src/lib.rs index b8ba21365d..e8d747a010 100644 --- a/libsql-sqlite3/test/rust_suite/src/lib.rs +++ b/libsql-sqlite3/test/rust_suite/src/lib.rs @@ -2,6 +2,8 @@ mod alter_column; mod random_rowid; mod virtual_wal; +#[cfg(test)] +mod extensions; #[cfg(all(test, feature = "udf"))] mod user_defined_functions;