MCPcopy Create free account
hub / github.com/libgit2/git2go / TestMempack

Function TestMempack

mempack_test.go:8–60  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestMempack(t *testing.T) {
9 t.Parallel()
10
11 odb, err := NewOdb()
12 checkFatal(t, err)
13
14 repo, err := NewRepositoryWrapOdb(odb)
15 checkFatal(t, err)
16
17 mempack, err := NewMempack(odb)
18 checkFatal(t, err)
19
20 id, err := odb.Write([]byte("hello, world!"), ObjectBlob)
21 checkFatal(t, err)
22
23 expectedId, err := NewOid("30f51a3fba5274d53522d0f19748456974647b4f")
24 checkFatal(t, err)
25 if !expectedId.Equal(id) {
26 t.Errorf("mismatched id. expected %v, got %v", expectedId.String(), id.String())
27 }
28
29 // The object should be available from the odb.
30 {
31 obj, err := odb.Read(expectedId)
32 checkFatal(t, err)
33 defer obj.Free()
34 }
35
36 data, err := mempack.Dump(repo)
37 checkFatal(t, err)
38
39 expectedData := []byte{
40 0x50, 0x41, 0x43, 0x4b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
41 0x02, 0x9d, 0x08, 0x82, 0x3b, 0xd8, 0xa8, 0xea, 0xb5, 0x10, 0xad, 0x6a,
42 0xc7, 0x5c, 0x82, 0x3c, 0xfd, 0x3e, 0xd3, 0x1e,
43 }
44 if !bytes.Equal(expectedData, data) {
45 t.Errorf("mismatched mempack data. expected %v, got %v", expectedData, data)
46 }
47
48 mempack.Reset()
49
50 // After the reset, the object should now be unavailable.
51 {
52 obj, err := odb.Read(expectedId)
53 if err == nil {
54 t.Errorf("object %s unexpectedly found", obj.Id().String())
55 obj.Free()
56 } else if !IsErrorCode(err, ErrorCodeNotFound) {
57 t.Errorf("unexpected error %v", err)
58 }
59 }
60}

Callers

nothing calls this directly

Calls 14

WriteMethod · 0.95
EqualMethod · 0.95
StringMethod · 0.95
ReadMethod · 0.95
DumpMethod · 0.95
ResetMethod · 0.95
NewOdbFunction · 0.85
checkFatalFunction · 0.85
NewRepositoryWrapOdbFunction · 0.85
NewMempackFunction · 0.85
NewOidFunction · 0.85
IsErrorCodeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…