Add some tests

This should prevent regressions in the future.
This commit is contained in:
lhchavez 2018-12-28 04:42:09 +00:00
parent 344dc33fae
commit ab3470030b
1 changed files with 13 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package git
import ( import (
"errors" "errors"
"io" "io"
"io/ioutil"
"testing" "testing"
) )
@ -47,22 +48,29 @@ func TestOdbStream(t *testing.T) {
str := "hello, world!" str := "hello, world!"
stream, error := odb.NewWriteStream(int64(len(str)), ObjectBlob) writeStream, error := odb.NewWriteStream(int64(len(str)), ObjectBlob)
checkFatal(t, error) checkFatal(t, error)
n, error := io.WriteString(stream, str) n, error := io.WriteString(writeStream, str)
checkFatal(t, error) checkFatal(t, error)
if n != len(str) { if n != len(str) {
t.Fatalf("Bad write length %v != %v", n, len(str)) t.Fatalf("Bad write length %v != %v", n, len(str))
} }
error = stream.Close() error = writeStream.Close()
checkFatal(t, error) checkFatal(t, error)
expectedId, error := NewOid("30f51a3fba5274d53522d0f19748456974647b4f") expectedId, error := NewOid("30f51a3fba5274d53522d0f19748456974647b4f")
checkFatal(t, error) checkFatal(t, error)
if stream.Id.Cmp(expectedId) != 0 { if writeStream.Id.Cmp(expectedId) != 0 {
t.Fatal("Wrong data written") t.Fatal("Wrong data written")
} }
readStream, error := odb.NewReadStream(&writeStream.Id)
checkFatal(t, error)
data, error := ioutil.ReadAll(readStream)
if str != string(data) {
t.Fatalf("Wrong data read %v != %v", str, string(data))
}
} }
func TestOdbHash(t *testing.T) { func TestOdbHash(t *testing.T) {