Add test for slice-to-slice and GCo pointer detection
diff --git a/.travis.yml b/.travis.yml
index f796389..016cf2d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,6 +10,7 @@
- 1.3
- 1.4
- 1.5
+ - 1.6
- tip
matrix:
diff --git a/blob_test.go b/blob_test.go
index 2b5ec4f..652c50c 100644
--- a/blob_test.go
+++ b/blob_test.go
@@ -1,9 +1,21 @@
package git
import (
+ "bytes"
"testing"
)
+type bufWrapper struct {
+ buf [64]byte
+ pointer []byte
+}
+
+func doublePointerBytes() []byte {
+ o := &bufWrapper{}
+ o.pointer = o.buf[0:10]
+ return o.pointer[0:1]
+}
+
func TestCreateBlobFromBuffer(t *testing.T) {
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
@@ -14,4 +26,18 @@
if id.String() != "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391" {
t.Fatal("Empty buffer did not deliver empty blob id")
}
+
+ for _, data := range []([]byte){[]byte("hello there"), doublePointerBytes()} {
+ expected := make([]byte, len(data))
+ copy(expected, data)
+ id, err = repo.CreateBlobFromBuffer(data)
+ checkFatal(t, err)
+
+ blob, err := repo.LookupBlob(id)
+ checkFatal(t, err)
+ if !bytes.Equal(blob.Contents(), expected) {
+ t.Fatal("Loaded bytes don't match original bytes:",
+ blob.Contents(), "!=", expected)
+ }
+ }
}