summaryrefslogtreecommitdiff
path: root/odb_test.go
diff options
context:
space:
mode:
authorMichel Lespinasse <[email protected]>2018-07-03 16:43:07 -0700
committerMichel Lespinasse <[email protected]>2018-07-03 16:43:07 -0700
commitbdca40d27558337f2aa84856b0dd8c6b1b6bb5c8 (patch)
treecdac7016c796c77ca3288290bb7c9570a741ce3d /odb_test.go
parenta2de5abababeb291f269fe254fc0341e5323af3f (diff)
git2go: small fixes to odb module
- Fix couple cgo issues in odb.Write() and odb.Hash(). This is the same issue - and same solution - as repo.CreateBlobFromBuffer() used to have. - Add test for odb.Read()
Diffstat (limited to 'odb_test.go')
-rw-r--r--odb_test.go33
1 files changed, 25 insertions, 8 deletions
diff --git a/odb_test.go b/odb_test.go
index 3d22fc9..8502c36 100644
--- a/odb_test.go
+++ b/odb_test.go
@@ -1,12 +1,13 @@
package git
import (
+ "bytes"
"errors"
"io"
"testing"
)
-func TestOdbReadHeader(t *testing.T) {
+func TestOdbRead(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@@ -26,13 +27,27 @@ func TestOdbReadHeader(t *testing.T) {
if err != nil {
t.Fatalf("ReadHeader: %v", err)
}
-
+
if sz != uint64(len(data)) {
t.Errorf("ReadHeader got size %d, want %d", sz, len(data))
}
if typ != ObjectBlob {
t.Errorf("ReadHeader got object type %s", typ)
}
+
+ obj, err := odb.Read(id)
+ if err != nil {
+ t.Fatalf("Read: %v", err)
+ }
+ if !bytes.Equal(obj.Data(), data) {
+ t.Errorf("Read got wrong data")
+ }
+ if sz := obj.Len(); sz != uint64(len(data)) {
+ t.Errorf("Read got size %d, want %d", sz, len(data))
+ }
+ if typ := obj.Type(); typ != ObjectBlob {
+ t.Errorf("Read got object type %s", typ)
+ }
}
func TestOdbStream(t *testing.T) {
@@ -82,14 +97,16 @@ committer John Doe <[email protected]> 1390682018 +0000
Initial commit.`
- oid, error := odb.Hash([]byte(str), ObjectCommit)
- checkFatal(t, error)
+ for _, data := range [][]byte{[]byte(str), doublePointerBytes()} {
+ oid, error := odb.Hash(data, ObjectCommit)
+ checkFatal(t, error)
- coid, error := odb.Write([]byte(str), ObjectCommit)
- checkFatal(t, error)
+ coid, error := odb.Write(data, ObjectCommit)
+ checkFatal(t, error)
- if oid.Cmp(coid) != 0 {
- t.Fatal("Hash and write Oids are different")
+ if oid.Cmp(coid) != 0 {
+ t.Fatal("Hash and write Oids are different")
+ }
}
}