Add some tests for Index

Including making the default :undefined, so the NIF doesn't get
upset. Implementing the Access protocol would require a struct, so we
may or may not want that.
This commit is contained in:
Carlos Martín Nieto
2014-08-03 15:03:03 +02:00
parent fffdb47032
commit ccc0cc1f80
2 changed files with 52 additions and 2 deletions

44
test/index_test.exs Normal file
View File

@@ -0,0 +1,44 @@
defmodule IndexTest do
use ExUnit.Case
use Geef
alias Geef.Index
alias Geef.Index.Entry
import RepoHelpers
setup do
{repo, path} = tmp_bare()
Process.link(repo)
on_exit(fn -> File.rm_rf!(path) end)
{:ok, [repo: repo, path: path]}
end
test "add an entry to the index", meta do
repo = meta[:repo]
content = "This is some text that will go in a file"
{:ok, odb} = Repository.odb(repo)
{:ok, id} = Odb.write(odb, content, :blob)
assert id == Oid.parse("c300118399f01fe52b316061b5d32beb27e0adfd")
{:ok, idx} = Index.new
{now_mega, now_secs, _} = :os.timestamp()
time = now_mega * 1000000 + now_secs
entry = %Geef.Index.Entry{mode: 0o100644, id: id, path: "README", size: byte_size(content), mtime: time}
:ok = Index.add(idx, entry)
{:ok, tree_id} = Index.write_tree(idx, repo)
expected = Oid.parse("5a20bbbf65ea75ad4d9f995d179156824ccca3a1")
assert tree_id == expected
{:ok, entry1} = Index.get(idx, "README", 0)
# entry2 = idx["README"]
# assert entry1 == entry2
assert entry1.size == byte_size(content)
Repository.stop(repo)
end
end