From 1f74e54af2754473e69a256beff7435b2117adda Mon Sep 17 00:00:00 2001 From: Ryan Schmukler Date: Tue, 16 Aug 2016 16:37:33 -0700 Subject: [PATCH] test(): add basic tests --- test/rox_test.exs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/test/rox_test.exs b/test/rox_test.exs index c62035c..7c5ce35 100644 --- a/test/rox_test.exs +++ b/test/rox_test.exs @@ -1,8 +1,33 @@ defmodule RoxTest do - use ExUnit.Case + use ExUnit.Case, async: false doctest Rox - test "the truth" do - assert 1 + 1 == 2 + setup do + path = Path.join(__DIR__, "test.rocksdb") + {:ok, db} = Rox.open(path, create_if_missing: true) + + on_exit fn -> + Rox.close(db) + File.rm_rf(path) + :ok + end + + {:ok, %{db: db}} + end + + test "simple put and get", %{db: db} do + assert :not_found = Rox.get(db, "key") + :ok = Rox.put(db, "key", "val") + + assert {:ok, "val"} = Rox.get(db, "key") + end + + test "stream_keys", %{db: db} do + :ok = Rox.put(db, "key", "val") + + count = Rox.stream_keys(db) + |> Enum.count + + assert count == 1 end end