-
Notifications
You must be signed in to change notification settings - Fork 128
/
tree_blob_test.go
57 lines (45 loc) · 1.07 KB
/
tree_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
// Copyright 2020 The Gogs Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package git
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestTree_TreeEntry(t *testing.T) {
tree, err := testrepo.LsTree("master")
if err != nil {
t.Fatal(err)
}
e, err := tree.TreeEntry("")
if err != nil {
t.Fatal(err)
}
assert.Equal(t, tree.id, e.ID())
assert.Equal(t, ObjectTree, e.Type())
assert.True(t, e.IsTree())
}
func TestTree_Blob(t *testing.T) {
tree, err := testrepo.LsTree("d58e3ef9f123eea6857161c79275ee22b228f659")
if err != nil {
t.Fatal(err)
}
t.Run("not a blob", func(t *testing.T) {
_, err := tree.Blob("src")
assert.Equal(t, ErrNotBlob, err)
})
t.Run("get a blob", func(t *testing.T) {
b, err := tree.Blob("README.txt")
if err != nil {
t.Fatal(err)
}
assert.True(t, b.IsBlob())
})
t.Run("get an executable as blob", func(t *testing.T) {
b, err := tree.Blob("run.sh")
if err != nil {
t.Fatal(err)
}
assert.True(t, b.IsExec())
})
}