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

Function TestCreateBlobFromBuffer

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

Source from the content-addressed store, hash-verified

17}
18
19func TestCreateBlobFromBuffer(t *testing.T) {
20 t.Parallel()
21 repo := createTestRepo(t)
22 defer cleanupTestRepo(t, repo)
23
24 id, err := repo.CreateBlobFromBuffer(make([]byte, 0))
25 checkFatal(t, err)
26
27 if id.String() != "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391" {
28 t.Fatal("Empty buffer did not deliver empty blob id")
29 }
30
31 tests := []struct {
32 data []byte
33 isBinary bool
34 }{
35 {
36 data: []byte("hello there"),
37 isBinary: false,
38 },
39 {
40 data: doublePointerBytes(),
41 isBinary: true,
42 },
43 }
44 for _, tt := range tests {
45 data := tt.data
46 id, err = repo.CreateBlobFromBuffer(data)
47 checkFatal(t, err)
48
49 blob, err := repo.LookupBlob(id)
50 checkFatal(t, err)
51 if !bytes.Equal(blob.Contents(), data) {
52 t.Fatal("Loaded bytes don't match original bytes:",
53 blob.Contents(), "!=", data)
54 }
55 want := tt.isBinary
56 if got := blob.IsBinary(); got != want {
57 t.Fatalf("IsBinary() = %v, want %v", got, want)
58 }
59 }
60}

Callers

nothing calls this directly

Calls 10

createTestRepoFunction · 0.85
cleanupTestRepoFunction · 0.85
checkFatalFunction · 0.85
doublePointerBytesFunction · 0.85
CreateBlobFromBufferMethod · 0.80
LookupBlobMethod · 0.80
EqualMethod · 0.80
ContentsMethod · 0.80
IsBinaryMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…