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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
package ref
import (
"testing"
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)
func TestBuildLocalBranch(t *testing.T) {
testCases := []struct {
desc string
in *gitalypb.GitCommit
out *gitalypb.FindLocalBranchResponse
}{
{
desc: "all required fields present",
in: &gitalypb.GitCommit{
Id: "b83d6e391c22777fca1ed3012fce84f633d7fed0",
Subject: []byte("Merge branch 'branch-merged' into 'master'"),
Body: []byte("Merge branch 'branch-merged' into 'master'\r\n\r\nadds bar folder and branch-test text file to check Repository merged_to_root_ref method\r\n\r\n\r\n\r\nSee merge request !12"),
Author: &gitalypb.CommitAuthor{
Name: []byte("Job van der Voort"),
Email: []byte("job@gitlab.com"),
Date: ×tamp.Timestamp{Seconds: 1474987066},
Timezone: []byte("+0200"),
},
Committer: &gitalypb.CommitAuthor{
Name: []byte("Job van der Voort"),
Email: []byte("job@gitlab.com"),
Date: ×tamp.Timestamp{Seconds: 1474987066},
Timezone: []byte("+0200"),
},
ParentIds: []string{
"1b12f15a11fc6e62177bef08f47bc7b5ce50b141",
"498214de67004b1da3d820901307bed2a68a8ef6",
},
BodySize: 162,
},
out: &gitalypb.FindLocalBranchResponse{
Name: []byte("my-branch"),
CommitId: "b83d6e391c22777fca1ed3012fce84f633d7fed0",
CommitSubject: []byte("Merge branch 'branch-merged' into 'master'"),
CommitAuthor: &gitalypb.FindLocalBranchCommitAuthor{
Name: []byte("Job van der Voort"),
Email: []byte("job@gitlab.com"),
Date: ×tamp.Timestamp{Seconds: 1474987066},
Timezone: []byte("+0200"),
},
CommitCommitter: &gitalypb.FindLocalBranchCommitAuthor{
Name: []byte("Job van der Voort"),
Email: []byte("job@gitlab.com"),
Date: ×tamp.Timestamp{Seconds: 1474987066},
Timezone: []byte("+0200"),
},
Commit: &gitalypb.GitCommit{
Id: "b83d6e391c22777fca1ed3012fce84f633d7fed0",
Subject: []byte("Merge branch 'branch-merged' into 'master'"),
Body: []byte("Merge branch 'branch-merged' into 'master'\r\n\r\nadds bar folder and branch-test text file to check Repository merged_to_root_ref method\r\n\r\n\r\n\r\nSee merge request !12"),
Author: &gitalypb.CommitAuthor{
Name: []byte("Job van der Voort"),
Email: []byte("job@gitlab.com"),
Date: ×tamp.Timestamp{Seconds: 1474987066},
Timezone: []byte("+0200"),
},
Committer: &gitalypb.CommitAuthor{
Name: []byte("Job van der Voort"),
Email: []byte("job@gitlab.com"),
Date: ×tamp.Timestamp{Seconds: 1474987066},
Timezone: []byte("+0200"),
},
ParentIds: []string{"1b12f15a11fc6e62177bef08f47bc7b5ce50b141", "498214de67004b1da3d820901307bed2a68a8ef6"},
BodySize: 162,
},
},
},
{
desc: "missing author",
in: &gitalypb.GitCommit{
Id: "b83d6e391c22777fca1ed3012fce84f633d7fed0",
Subject: []byte("Merge branch 'branch-merged' into 'master'"),
Body: []byte("Merge branch 'branch-merged' into 'master'\r\n\r\nadds bar folder and branch-test text file to check Repository merged_to_root_ref method\r\n\r\n\r\n\r\nSee merge request !12"),
Committer: &gitalypb.CommitAuthor{
Name: []byte("Job van der Voort"),
Email: []byte("job@gitlab.com"),
Date: ×tamp.Timestamp{Seconds: 1474987066},
Timezone: []byte("+0200"),
},
ParentIds: []string{
"1b12f15a11fc6e62177bef08f47bc7b5ce50b141",
"498214de67004b1da3d820901307bed2a68a8ef6",
},
BodySize: 162,
},
out: &gitalypb.FindLocalBranchResponse{
Name: []byte("my-branch"),
CommitId: "b83d6e391c22777fca1ed3012fce84f633d7fed0",
CommitSubject: []byte("Merge branch 'branch-merged' into 'master'"),
CommitAuthor: nil,
CommitCommitter: &gitalypb.FindLocalBranchCommitAuthor{
Name: []byte("Job van der Voort"),
Email: []byte("job@gitlab.com"),
Date: ×tamp.Timestamp{Seconds: 1474987066},
Timezone: []byte("+0200"),
},
Commit: &gitalypb.GitCommit{
Id: "b83d6e391c22777fca1ed3012fce84f633d7fed0",
Subject: []byte("Merge branch 'branch-merged' into 'master'"),
Body: []byte("Merge branch 'branch-merged' into 'master'\r\n\r\nadds bar folder and branch-test text file to check Repository merged_to_root_ref method\r\n\r\n\r\n\r\nSee merge request !12"),
Committer: &gitalypb.CommitAuthor{
Name: []byte("Job van der Voort"),
Email: []byte("job@gitlab.com"),
Date: ×tamp.Timestamp{Seconds: 1474987066},
Timezone: []byte("+0200"),
},
ParentIds: []string{"1b12f15a11fc6e62177bef08f47bc7b5ce50b141", "498214de67004b1da3d820901307bed2a68a8ef6"},
BodySize: 162,
},
},
},
{
desc: "missing committer",
in: &gitalypb.GitCommit{
Id: "b83d6e391c22777fca1ed3012fce84f633d7fed0",
Subject: []byte("Merge branch 'branch-merged' into 'master'"),
Body: []byte("Merge branch 'branch-merged' into 'master'\r\n\r\nadds bar folder and branch-test text file to check Repository merged_to_root_ref method\r\n\r\n\r\n\r\nSee merge request !12"),
Author: &gitalypb.CommitAuthor{
Name: []byte("Job van der Voort"),
Email: []byte("job@gitlab.com"),
Date: ×tamp.Timestamp{Seconds: 1474987066},
Timezone: []byte("+0200"),
},
ParentIds: []string{
"1b12f15a11fc6e62177bef08f47bc7b5ce50b141",
"498214de67004b1da3d820901307bed2a68a8ef6",
},
BodySize: 162,
},
out: &gitalypb.FindLocalBranchResponse{
Name: []byte("my-branch"),
CommitId: "b83d6e391c22777fca1ed3012fce84f633d7fed0",
CommitSubject: []byte("Merge branch 'branch-merged' into 'master'"),
CommitAuthor: &gitalypb.FindLocalBranchCommitAuthor{
Name: []byte("Job van der Voort"),
Email: []byte("job@gitlab.com"),
Date: ×tamp.Timestamp{Seconds: 1474987066},
Timezone: []byte("+0200"),
},
CommitCommitter: nil,
Commit: &gitalypb.GitCommit{
Id: "b83d6e391c22777fca1ed3012fce84f633d7fed0",
Subject: []byte("Merge branch 'branch-merged' into 'master'"),
Body: []byte("Merge branch 'branch-merged' into 'master'\r\n\r\nadds bar folder and branch-test text file to check Repository merged_to_root_ref method\r\n\r\n\r\n\r\nSee merge request !12"),
Author: &gitalypb.CommitAuthor{
Name: []byte("Job van der Voort"),
Email: []byte("job@gitlab.com"),
Date: ×tamp.Timestamp{Seconds: 1474987066},
Timezone: []byte("+0200"),
},
ParentIds: []string{"1b12f15a11fc6e62177bef08f47bc7b5ce50b141", "498214de67004b1da3d820901307bed2a68a8ef6"},
BodySize: 162,
},
},
},
{
desc: "nil commit",
in: nil,
out: &gitalypb.FindLocalBranchResponse{
Name: []byte("my-branch"),
},
},
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
require.Equal(t, *tc.out, *buildLocalBranch([]byte("my-branch"), tc.in))
})
}
}
|