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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
package log
import (
"bytes"
"testing"
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)
func TestParseRawCommit(t *testing.T) {
info := &catfile.ObjectInfo{
Oid: "a984dfa4dee018c6d5f5f57ffec0d0e22763df16",
Type: "commit",
}
// Valid-but-interesting commits should be test at the FindCommit level.
// Invalid objects (that Git would complain about during fsck) can be
// tested here.
//
// Once a repository contains a pathological object it can be hard to get
// rid of it. Because of this I think it's nicer to ignore such objects
// than to throw hard errors.
testCases := []struct {
desc string
in []byte
out *gitalypb.GitCommit
}{
{
desc: "empty commit object",
in: []byte{},
out: &gitalypb.GitCommit{Id: info.Oid},
},
{
desc: "no email",
in: []byte("author Jane Doe"),
out: &gitalypb.GitCommit{
Id: info.Oid,
Author: &gitalypb.CommitAuthor{Name: []byte("Jane Doe")},
},
},
{
desc: "unmatched <",
in: []byte("author Jane Doe <janedoe@example.com"),
out: &gitalypb.GitCommit{
Id: info.Oid,
Author: &gitalypb.CommitAuthor{Name: []byte("Jane Doe")},
},
},
{
desc: "unmatched >",
in: []byte("author Jane Doe janedoe@example.com>"),
out: &gitalypb.GitCommit{
Id: info.Oid,
Author: &gitalypb.CommitAuthor{Name: []byte("Jane Doe janedoe@example.com>")},
},
},
{
desc: "missing date",
in: []byte("author Jane Doe <janedoe@example.com> "),
out: &gitalypb.GitCommit{
Id: info.Oid,
Author: &gitalypb.CommitAuthor{Name: []byte("Jane Doe"), Email: []byte("janedoe@example.com")},
},
},
{
desc: "date too high",
in: []byte("author Jane Doe <janedoe@example.com> 9007199254740993 +0200"),
out: &gitalypb.GitCommit{
Id: info.Oid,
Author: &gitalypb.CommitAuthor{
Name: []byte("Jane Doe"),
Email: []byte("janedoe@example.com"),
Date: ×tamp.Timestamp{Seconds: 9223371974719179007},
},
},
},
{
desc: "date negative",
in: []byte("author Jane Doe <janedoe@example.com> -1 +0200"),
out: &gitalypb.GitCommit{
Id: info.Oid,
Author: &gitalypb.CommitAuthor{
Name: []byte("Jane Doe"),
Email: []byte("janedoe@example.com"),
Date: ×tamp.Timestamp{Seconds: 9223371974719179007},
},
},
},
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
info.Size = int64(len(tc.in))
out, err := parseRawCommit(bytes.NewBuffer(tc.in), info)
require.NoError(t, err, "parse error")
require.Equal(t, tc.out, out)
})
}
}
|