Current section

Files

Jump to
fsdb test fsdb_test.exs
Raw

test/fsdb_test.exs

defmodule FsdbTest do
use ExUnit.Case
doctest Fsdb
@path "_build/test"
test "crud" do
path = Path.expand(@path)
File.rm_rf!(path)
{:ok, pid} = Fsdb.start_link([path: path])
assert File.exists?(path)
assert :ok == Fsdb.create(pid, "table1")
assert File.exists?(Path.join(path, "table1"))
assert File.exists?(Path.join([path, "table1", "row.id"]))
assert [] == Fsdb.list(pid, "table1")
assert {:not_found, "table1", 1} == Fsdb.fetch(pid, "table1", 1)
assert {1, "row1"} == Fsdb.insert(pid, "table1", "row1")
assert File.exists?(Path.join([path, "table1", "row.000001"]))
assert {1, "row1"} == Fsdb.fetch(pid, "table1", 1)
assert [{1, "row1"}] == Fsdb.list(pid, "table1")
assert {1, "row1+"} == Fsdb.update(pid, "table1", 1, "row1+")
assert {1, "row1+"} == Fsdb.fetch(pid, "table1", 1)
assert {1, "row1+"} == Fsdb.delete(pid, "table1", 1)
assert !File.exists?(Path.join([path, "table1", "row.000001"]))
assert [] == Fsdb.list(pid, "table1")
assert {:not_found, "table1", 1} == Fsdb.fetch(pid, "table1", 1)
assert {2, "row2"} == Fsdb.insert(pid, "table1", "row2")
assert {3, "row3"} == Fsdb.insert(pid, "table1", "row3")
#FIXME how to ensure order?
assert [{2, "row2"}, {3, "row3"}] == Fsdb.list(pid, "table1")
assert :ok == Fsdb.drop(pid, "table1")
assert !File.exists?(Path.join(path, "table1"))
Fsdb.stop(pid)
#FIXME delay required
#assert !Process.alive?(pid)
end
end