forked from libgit2/git2go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree_test.go
65 lines (52 loc) · 1.33 KB
/
tree_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
61
62
63
64
65
package git
import "testing"
func TestTreeEntryById(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
_, treeID := seedTestRepo(t, repo)
tree, err := repo.LookupTree(treeID)
checkFatal(t, err)
id, err := NewOid("257cc5642cb1a054f08cc83f2d943e56fd3ebe99")
checkFatal(t, err)
entry := tree.EntryById(id)
if entry == nil {
t.Fatalf("entry id %v was not found", id)
}
}
func TestTreeBuilderInsert(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
subTree, err := repo.TreeBuilder()
if err != nil {
t.Fatalf("TreeBuilder: %v", err)
}
defer subTree.Free()
odb, err := repo.Odb()
if err != nil {
t.Fatalf("repo.Odb: %v", err)
}
blobId, err := odb.Write([]byte("hello"), ObjectBlob)
if err != nil {
t.Fatalf("odb.Write: %v", err)
}
if err = subTree.Insert("subfile", blobId, FilemodeBlobExecutable); err != nil {
t.Fatalf("TreeBuilder.Insert: %v", err)
}
treeID, err := subTree.Write()
if err != nil {
t.Fatalf("TreeBuilder.Write: %v", err)
}
tree, err := repo.LookupTree(treeID)
if err != nil {
t.Fatalf("LookupTree: %v", err)
}
entry, err := tree.EntryByPath("subfile")
if err != nil {
t.Fatalf("tree.EntryByPath(%q): %v", "subfile", err)
}
if !entry.Id.Equal(blobId) {
t.Fatalf("got oid %v, want %v", entry.Id, blobId)
}
}