From 24c928a03ba5143172a5276e898ce3618b470f8e Mon Sep 17 00:00:00 2001 From: Cocoa Date: Sun, 6 Aug 2023 11:04:49 +0100 Subject: [PATCH] added tests for loading custom driver (#25) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * added tests for loading custom driver * ignore duckdb by default * include duckdb tests on linux ci Co-authored-by: José Valim --------- Co-authored-by: José Valim --- .github/workflows/ci.yml | 2 +- test/adbc_database_test.exs | 44 +++++++++++++++++++++++++++++++++++++ test/test_helper.exs | 2 ++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ca12ceb..68333f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,7 +43,7 @@ jobs: - name: Compile and Test run: | mix deps.get - mix test + mix test --include duckdb windows: if: "!contains(github.event.pull_request.labels.*.name, 'skip ci')" diff --git a/test/adbc_database_test.exs b/test/adbc_database_test.exs index db175dd..52e71c2 100644 --- a/test/adbc_database_test.exs +++ b/test/adbc_database_test.exs @@ -3,6 +3,36 @@ defmodule Adbc.DatabaseTest do doctest Adbc.Database alias Adbc.Database + setup_all do + {:ok, zip_data} = + Adbc.Helper.download( + "https://github.com/duckdb/duckdb/releases/download/v0.8.1/libduckdb-linux-amd64.zip", + false + ) + + tmp_dir = System.tmp_dir!() + cache_path = Path.join(tmp_dir, "libduckdb-linux-amd64.zip") + File.write!(cache_path, zip_data) + + cache_path = String.to_charlist(cache_path) + {:ok, zip_handle} = :zip.zip_open(cache_path, [:memory]) + {:ok, zip_files} = :zip.table(cache_path) + + for {:zip_file, filename, _, _, _, _} <- zip_files, + Path.extname(filename) == ".so" do + {:ok, {filename, file_data}} = :zip.zip_get(filename, zip_handle) + + filename = to_string(filename) + + filepath = Path.join(tmp_dir, filename) + File.write!(filepath, file_data) + end + + :ok = :zip.zip_close(zip_handle) + + %{path: Path.join(tmp_dir, "libduckdb.so"), entrypoint: "duckdb_adbc_init"} + end + describe "start_link" do test "starts a process" do assert {:ok, _} = Database.start_link(driver: :sqlite) @@ -33,4 +63,18 @@ defmodule Adbc.DatabaseTest do assert Exception.message(error) == "[SQLite] Unknown database option who_knows=123" end end + + describe "load custom driver" do + @describetag :duckdb + + test "load duckdb", %{path: path, entrypoint: entrypoint} do + assert {:ok, _} = Database.start_link(driver: path, entrypoint: entrypoint) + end + + test "load duckdb with invalid entrypoint", %{path: path} do + assert {:error, %Adbc.Error{} = error} = Database.start_link(driver: path, entrypoint: "entrypoint") + + assert Exception.message(error) =~ "dlsym(entrypoint) failed:" + end + end end diff --git a/test/test_helper.exs b/test/test_helper.exs index fe8b4a3..28819ac 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -8,4 +8,6 @@ exclude = [:postgresql] end +exclude = exclude ++ [:duckdb] + ExUnit.start(exclude: exclude)