forked from libgit2/git2go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blob_test.go
60 lines (52 loc) · 1.12 KB
/
blob_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
id, err := repo.CreateBlobFromBuffer(make([]byte, 0))
checkFatal(t, err)
if id.String() != "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391" {
t.Fatal("Empty buffer did not deliver empty blob id")
}
tests := []struct {
data []byte
isBinary bool
}{
{
data: []byte("hello there"),
isBinary: false,
},
{
data: doublePointerBytes(),
isBinary: true,
},
}
for _, tt := range tests {
data := tt.data
id, err = repo.CreateBlobFromBuffer(data)
checkFatal(t, err)
blob, err := repo.LookupBlob(id)
checkFatal(t, err)
if !bytes.Equal(blob.Contents(), data) {
t.Fatal("Loaded bytes don't match original bytes:",
blob.Contents(), "!=", data)
}
want := tt.isBinary
if got := blob.IsBinary(); got != want {
t.Fatalf("IsBinary() = %v, want %v", got, want)
}
}
}