Skip to content

Commit

Permalink
added tests for loading custom driver (#25)
Browse files Browse the repository at this point in the history
* added tests for loading custom driver

* ignore duckdb by default

* include duckdb tests on linux ci

Co-authored-by: José Valim <[email protected]>

---------

Co-authored-by: José Valim <[email protected]>
  • Loading branch information
cocoa-xu and josevalim authored Aug 6, 2023
1 parent 4ba1de7 commit 24c928a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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')"
Expand Down
44 changes: 44 additions & 0 deletions test/adbc_database_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ exclude =
[:postgresql]
end

exclude = exclude ++ [:duckdb]

ExUnit.start(exclude: exclude)

0 comments on commit 24c928a

Please sign in to comment.