-
Notifications
You must be signed in to change notification settings - Fork 318
/
mempack_test.go
60 lines (48 loc) · 1.35 KB
/
mempack_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"
)
func TestMempack(t *testing.T) {
t.Parallel()
odb, err := NewOdb()
checkFatal(t, err)
repo, err := NewRepositoryWrapOdb(odb)
checkFatal(t, err)
mempack, err := NewMempack(odb)
checkFatal(t, err)
id, err := odb.Write([]byte("hello, world!"), ObjectBlob)
checkFatal(t, err)
expectedId, err := NewOid("30f51a3fba5274d53522d0f19748456974647b4f")
checkFatal(t, err)
if !expectedId.Equal(id) {
t.Errorf("mismatched id. expected %v, got %v", expectedId.String(), id.String())
}
// The object should be available from the odb.
{
obj, err := odb.Read(expectedId)
checkFatal(t, err)
defer obj.Free()
}
data, err := mempack.Dump(repo)
checkFatal(t, err)
expectedData := []byte{
0x50, 0x41, 0x43, 0x4b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
0x02, 0x9d, 0x08, 0x82, 0x3b, 0xd8, 0xa8, 0xea, 0xb5, 0x10, 0xad, 0x6a,
0xc7, 0x5c, 0x82, 0x3c, 0xfd, 0x3e, 0xd3, 0x1e,
}
if !bytes.Equal(expectedData, data) {
t.Errorf("mismatched mempack data. expected %v, got %v", expectedData, data)
}
mempack.Reset()
// After the reset, the object should now be unavailable.
{
obj, err := odb.Read(expectedId)
if err == nil {
t.Errorf("object %s unexpectedly found", obj.Id().String())
obj.Free()
} else if !IsErrorCode(err, ErrorCodeNotFound) {
t.Errorf("unexpected error %v", err)
}
}
}