-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathobject_test.go
86 lines (61 loc) · 2.09 KB
/
object_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package gitreader
import (
"bytes"
"compress/zlib"
"io/ioutil"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestParseCommitObject(t *testing.T) {
plain := []byte("commit 165\x00parent abcd\ntree b28f66668670da36a8618360d1f16f3415dfaa3f\nauthor Evan Phoenix <[email protected]> 1418539320 -0800\ncommitter Evan Phoenix <[email protected]> 1418539320 -0800\n\nadd Procfile\n")
var compress bytes.Buffer
zw := zlib.NewWriter(&compress)
zw.Write(plain)
zw.Close()
obj, err := ParseObject(&compress)
require.NoError(t, err)
assert.Equal(t, "commit", obj.Type)
assert.Equal(t, 165, int(obj.Size))
commit, err := obj.Commit()
require.NoError(t, err)
assert.Equal(t, "abcd", commit.Parent)
assert.Equal(t, "b28f66668670da36a8618360d1f16f3415dfaa3f", commit.Tree)
assert.Equal(t, "Evan Phoenix <[email protected]> 1418539320 -0800", commit.Author)
assert.Equal(t, "Evan Phoenix <[email protected]> 1418539320 -0800", commit.Committer)
assert.Equal(t, "add Procfile\n", commit.Message)
}
func TestParseTreeObject(t *testing.T) {
plain := []byte("tree 36\x00100644 Procfile\x00^\x7FE{\xB1s/C\x15\xF3\xB6\x19>\xE8^\xFD\xF7s]P")
var compress bytes.Buffer
zw := zlib.NewWriter(&compress)
zw.Write(plain)
zw.Close()
obj, err := ParseObject(&compress)
require.NoError(t, err)
assert.Equal(t, "tree", obj.Type)
assert.Equal(t, 36, int(obj.Size))
tree, err := obj.Tree()
require.NoError(t, err)
entry, ok := tree.Entries["Procfile"]
require.True(t, ok)
assert.Equal(t, "100644", entry.Permissions)
assert.Equal(t, "Procfile", entry.Name)
assert.Equal(t, "5e7f457bb1732f4315f3b6193ee85efdf7735d50", entry.Id)
}
func TestParseBlobObject(t *testing.T) {
plain := []byte("blob 10\x00web: puma\n")
var compress bytes.Buffer
zw := zlib.NewWriter(&compress)
zw.Write(plain)
zw.Close()
obj, err := ParseObject(&compress)
require.NoError(t, err)
assert.Equal(t, "blob", obj.Type)
assert.Equal(t, 10, int(obj.Size))
rdr, err := obj.Blob()
require.NoError(t, err)
blob, err := ioutil.ReadAll(rdr)
require.NoError(t, err)
assert.Equal(t, []byte("web: puma\n"), blob)
}