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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
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
trim bool
}{
{
tagName: fmt.Sprintf("%s-v1.0.2", t.Name()),
rev: "master^^^^",
message: strings.Repeat("a", helper.MaxCommitOrTagMessageSize+1),
trim: false,
},
{
tagName: fmt.Sprintf("%s-v1.0.0", t.Name()),
rev: "master^^^",
message: "Prod Release v1.0.0",
trim: true,
},
{
tagName: fmt.Sprintf("%s-v1.0.1", t.Name()),
rev: "master^^",
message: strings.Repeat("a", helper.MaxCommitOrTagMessageSize+1),
trim: true,
},
}
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, tagID, testCase.tagName, testCase.trim, true)
require.NoError(t, err)
if testCase.trim && 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
trimNewLine bool
}{
{
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"),
},
{
description: "tag with message with empty line and right side new line trimming",
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\n\n",
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"),
trimNewLine: true,
},
}
for _, tc := range testCases {
header, body, err := splitRawTag(bytes.NewReader([]byte(tc.tagContent)), tc.trimNewLine)
assert.Equal(t, tc.header, *header)
assert.Equal(t, tc.body, body)
assert.NoError(t, err)
}
}
|