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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
package log
import (
"bytes"
"fmt"
"strings"
"testing"
"gitlab.com/gitlab-org/gitaly/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/internal/helper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
)
func TestGetTag(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
testCases := []struct {
tagName string
rev string
message string
}{
{
tagName: fmt.Sprintf("%s-v1.0.0", t.Name()),
rev: "master^^^",
message: "Prod Release v1.0.0",
},
{
tagName: fmt.Sprintf("%s-v1.0.1", t.Name()),
rev: "master^^",
message: strings.Repeat("a", helper.MaxCommitOrTagMessageSize+1),
},
}
c, err := catfile.New(ctx, testRepo)
require.NoError(t, err)
for _, testCase := range testCases {
t.Run(testCase.tagName, func(t *testing.T) {
tagID := testhelper.CreateTag(t, testRepoPath, testCase.tagName, testCase.rev, &testhelper.CreateTagOpts{Message: testCase.message})
tag, err := GetTagCatfile(c, string(tagID), testCase.tagName)
require.NoError(t, err)
if len(testCase.message) >= helper.MaxCommitOrTagMessageSize {
testCase.message = testCase.message[:helper.MaxCommitOrTagMessageSize]
}
require.Equal(t, testCase.message, string(tag.Message))
require.Equal(t, testCase.tagName, string(tag.GetName()))
})
}
}
func TestSplitRawTag(t *testing.T) {
testCases := []struct {
description string
tagContent string
header tagHeader
body []byte
}{
{
description: "tag without a message",
tagContent: "object c92faf3e0a557270141be67f206d7cdb99bfc3a2\ntype commit\ntag v2.6.16.28\ntagger Adrian Bunk <bunk@stusta.de> 1156539089 +0200",
header: tagHeader{
oid: "c92faf3e0a557270141be67f206d7cdb99bfc3a2",
tagType: "commit",
tag: "v2.6.16.28",
tagger: "Adrian Bunk <bunk@stusta.de> 1156539089 +0200",
},
body: nil,
},
{
description: "tag with message",
tagContent: "object c92faf3e0a557270141be67f206d7cdb99bfc3a2\ntype commit\ntag v2.6.16.28\ntagger Adrian Bunk <bunk@stusta.de> 1156539089 +0200\n\nmessage",
header: tagHeader{
oid: "c92faf3e0a557270141be67f206d7cdb99bfc3a2",
tagType: "commit",
tag: "v2.6.16.28",
tagger: "Adrian Bunk <bunk@stusta.de> 1156539089 +0200",
},
body: []byte("message"),
},
{
description: "tag with empty message",
tagContent: "object c92faf3e0a557270141be67f206d7cdb99bfc3a2\ntype commit\ntag v2.6.16.28\ntagger Adrian Bunk <bunk@stusta.de> 1156539089 +0200\n\n",
header: tagHeader{
oid: "c92faf3e0a557270141be67f206d7cdb99bfc3a2",
tagType: "commit",
tag: "v2.6.16.28",
tagger: "Adrian Bunk <bunk@stusta.de> 1156539089 +0200",
},
body: []byte{},
},
{
description: "tag with message with empty line",
tagContent: "object c92faf3e0a557270141be67f206d7cdb99bfc3a2\ntype commit\ntag v2.6.16.28\ntagger Adrian Bunk <bunk@stusta.de> 1156539089 +0200\n\nHello world\n\nThis is a message",
header: tagHeader{
oid: "c92faf3e0a557270141be67f206d7cdb99bfc3a2",
tagType: "commit",
tag: "v2.6.16.28",
tagger: "Adrian Bunk <bunk@stusta.de> 1156539089 +0200",
},
body: []byte("Hello world\n\nThis is a message"),
},
}
for _, tc := range testCases {
header, body, err := splitRawTag(bytes.NewReader([]byte(tc.tagContent)))
assert.Equal(t, tc.header, *header)
assert.Equal(t, tc.body, body)
assert.NoError(t, err)
}
}
|