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
|
package catfile
import (
"testing"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
"google.golang.org/grpc/metadata"
)
func TestGetCommit(t *testing.T) {
ctx := testhelper.Context(t)
_, objectReader, _ := setupObjectReader(t, ctx)
ctx = metadata.NewIncomingContext(ctx, metadata.MD{})
const commitSha = "2d1db523e11e777e49377cfb22d368deec3f0793"
const commitMsg = "Correct test_env.rb path for adding branch\n"
const blobSha = "c60514b6d3d6bf4bec1030f70026e34dfbd69ad5"
testCases := []struct {
desc string
revision string
errStr string
}{
{
desc: "commit",
revision: commitSha,
},
{
desc: "not existing commit",
revision: "not existing revision",
errStr: "object not found",
},
{
desc: "blob sha",
revision: blobSha,
errStr: "object not found",
},
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
c, err := GetCommit(ctx, objectReader, git.Revision(tc.revision))
if tc.errStr == "" {
require.NoError(t, err)
require.Equal(t, commitMsg, string(c.Body))
} else {
require.EqualError(t, err, tc.errStr)
}
})
}
}
func TestGetCommitWithTrailers(t *testing.T) {
ctx := testhelper.Context(t)
cfg, objectReader, testRepo := setupObjectReader(t, ctx)
ctx = metadata.NewIncomingContext(ctx, metadata.MD{})
commit, err := GetCommitWithTrailers(ctx, gittest.NewCommandFactory(t, cfg), testRepo,
objectReader, "5937ac0a7beb003549fc5fd26fc247adbce4a52e")
require.NoError(t, err)
require.Equal(t, commit.Trailers, []*gitalypb.CommitTrailer{
{
Key: []byte("Signed-off-by"),
Value: []byte("Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>"),
},
})
}
|