Add test for slice-to-slice and GCo pointer detection
This commit is contained in:
parent
1670c49c7e
commit
3c1ba8c40e
|
@ -10,6 +10,7 @@ go:
|
|||
- 1.3
|
||||
- 1.4
|
||||
- 1.5
|
||||
- 1.6
|
||||
- tip
|
||||
|
||||
matrix:
|
||||
|
|
26
blob_test.go
26
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 @@ func TestCreateBlobFromBuffer(t *testing.T) {
|
|||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue