-
Notifications
You must be signed in to change notification settings - Fork 10
/
tag_test.go
66 lines (50 loc) · 1.67 KB
/
tag_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
package gitobj
import (
"bytes"
"crypto/sha1"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestTagTypeReturnsCorrectObjectType(t *testing.T) {
assert.Equal(t, TagObjectType, new(Tag).Type())
}
func TestTagEncode(t *testing.T) {
tag := &Tag{
Object: []byte("aaaaaaaaaaaaaaaaaaaa"),
ObjectType: CommitObjectType,
Name: "v2.4.0",
Tagger: "A U Thor <[email protected]>",
Message: "The quick brown fox jumps over the lazy dog.",
}
buf := new(bytes.Buffer)
n, err := tag.Encode(buf)
assert.Nil(t, err)
assert.EqualValues(t, buf.Len(), n)
assertLine(t, buf, "object 6161616161616161616161616161616161616161")
assertLine(t, buf, "type commit")
assertLine(t, buf, "tag v2.4.0")
assertLine(t, buf, "tagger A U Thor <[email protected]>")
assertLine(t, buf, "")
assertLine(t, buf, "The quick brown fox jumps over the lazy dog.")
assert.Equal(t, 0, buf.Len())
}
func TestTagDecode(t *testing.T) {
from := new(bytes.Buffer)
fmt.Fprintf(from, "object 6161616161616161616161616161616161616161\n")
fmt.Fprintf(from, "type commit\n")
fmt.Fprintf(from, "tag v2.4.0\n")
fmt.Fprintf(from, "tagger A U Thor <[email protected]>\n")
fmt.Fprintf(from, "\n")
fmt.Fprintf(from, "The quick brown fox jumps over the lazy dog.\n")
flen := from.Len()
tag := new(Tag)
n, err := tag.Decode(sha1.New(), from, int64(flen))
assert.Nil(t, err)
assert.Equal(t, n, flen)
assert.Equal(t, []byte("aaaaaaaaaaaaaaaaaaaa"), tag.Object)
assert.Equal(t, CommitObjectType, tag.ObjectType)
assert.Equal(t, "v2.4.0", tag.Name)
assert.Equal(t, "A U Thor <[email protected]>", tag.Tagger)
assert.Equal(t, "The quick brown fox jumps over the lazy dog.", tag.Message)
}