@@ -91,31 +91,59 @@ func (g *fakeCoalesceGerrit) GetCommitMessage(ctx context.Context, changeID stri
91
91
92
92
type securityVersionClient struct {
93
93
GerritClient
94
- tags []string
94
+ tags , branches []string
95
95
}
96
96
97
- func (c * securityVersionClient ) ListTags (ctx context.Context , project string ) ([]string , error ) {
97
+ func (c * securityVersionClient ) ListTags (_ context.Context , project string ) ([]string , error ) {
98
+ if project != "go" {
99
+ return nil , nil
100
+ }
98
101
return c .tags , nil
99
102
}
100
103
101
- func (c * securityVersionClient ) GetTag (ctx context.Context , project , tag string ) (gerrit.TagInfo , error ) {
104
+ func (c * securityVersionClient ) GetTag (_ context.Context , project , tag string ) (gerrit.TagInfo , error ) {
105
+ if project != "go" {
106
+ return gerrit.TagInfo {}, gerrit .ErrResourceNotExist
107
+ }
102
108
for _ , t := range c .tags {
103
109
if tag == t {
104
110
return gerrit.TagInfo {Created : gerrit .TimeStamp (time .Now ())}, nil
105
111
}
106
112
}
107
- return gerrit.TagInfo {}, errors .New ("not found" )
113
+ return gerrit.TagInfo {}, gerrit .ErrResourceNotExist
114
+ }
115
+
116
+ func (c * securityVersionClient ) ReadBranchHead (_ context.Context , project , branch string ) (string , error ) {
117
+ if project != "go" {
118
+ return "" , gerrit .ErrResourceNotExist
119
+ }
120
+ if ! slices .Contains (c .branches , branch ) {
121
+ return "" , gerrit .ErrResourceNotExist
122
+ }
123
+ return branch + "-head" , nil
108
124
}
109
125
110
126
func TestSecurityReleaseCoalesceTask (t * testing.T ) {
127
+ t .Run ("minors only" , func (t * testing.T ) {
128
+ testSecurityReleaseCoalesceTask (t , false )
129
+ })
130
+ t .Run ("minors with RC" , func (t * testing.T ) {
131
+ testSecurityReleaseCoalesceTask (t , true )
132
+ })
133
+ }
134
+
135
+ func testSecurityReleaseCoalesceTask (t * testing.T , withNextReleaseBranch bool ) {
136
+ publicTags := []string {"go1.3" , "go1.3.1" , "go1.4" , "go1.4.1" }
137
+ publicBranches := []string {"release-branch.go1.3" , "release-branch.go1.4" }
138
+ if withNextReleaseBranch {
139
+ publicBranches = append (publicBranches , "release-branch.go1.5" )
140
+ }
111
141
privRepo := NewFakeRepo (t , "go" )
112
142
privGerrit := & fakeCoalesceGerrit {FakeGerrit : NewFakeGerrit (t , privRepo ), cherryPicks : map [string ][]cherryPickedCommit {}, commitMessages : map [string ]string {}}
113
143
task := & SecurityReleaseCoalesceTask {
114
144
PrivateGerrit : privGerrit ,
115
145
Version : & VersionTasks {
116
- Gerrit : & securityVersionClient {
117
- tags : []string {"go1.3" , "go1.3.1" , "go1.4" , "go1.4.1" },
118
- },
146
+ Gerrit : & securityVersionClient {tags : publicTags , branches : publicBranches },
119
147
GoProject : "go" ,
120
148
},
121
149
}
@@ -152,9 +180,12 @@ other body`,
152
180
privRepo .Branch ("public" , head )
153
181
privRepo .Branch ("release-branch.go1.3" , head )
154
182
privRepo .Branch ("release-branch.go1.4" , head )
183
+ if withNextReleaseBranch {
184
+ privRepo .Branch ("release-branch.go1.5" , head )
185
+ }
155
186
156
187
wd := task .NewDefinition ()
157
- w , err := wf .Start (wd , map [string ]interface {} {
188
+ w , err := wf .Start (wd , map [string ]any {
158
189
"Security Patch CL Numbers" : []string {"1234" , "5678" },
159
190
})
160
191
if err != nil {
@@ -168,14 +199,18 @@ other body`,
168
199
}
169
200
170
201
// Check checkpoint branch has the expected number of submitted changes
171
- commits := len (strings .Split (string (privRepo .runGit ("log" , "go1.4.2-and-go1.3.2-checkpoint" , "--format=%H" )), "\n " )) - 1
202
+ checkpointBranch := "go1.4.2-go1.3.2-checkpoint"
203
+ if withNextReleaseBranch {
204
+ checkpointBranch = "go1.5rc1-go1.4.2-go1.3.2-checkpoint"
205
+ }
206
+ commits := len (strings .Split (string (privRepo .runGit ("log" , checkpointBranch , "--format=%H" )), "\n " )) - 1
172
207
if commits != 3 {
173
208
t .Errorf ("unexpected number of commits on checkpoint branch: got %d, want 3" , commits )
174
209
}
175
210
176
211
// Check each internal release branch has the expected cherry-picks
177
212
expected := map [string ][]cherryPickedCommit {
178
- "internal-release-branch.go1.4.2" : [] cherryPickedCommit {
213
+ "internal-release-branch.go1.4.2" : {
179
214
{
180
215
changeID : "1234" ,
181
216
message : `[release-branch.go1.4] subject: 1234
@@ -189,7 +224,7 @@ body`,
189
224
other body` ,
190
225
},
191
226
},
192
- "internal-release-branch.go1.3.2" : [] cherryPickedCommit {
227
+ "internal-release-branch.go1.3.2" : {
193
228
{
194
229
changeID : "1234" ,
195
230
message : `[release-branch.go1.3] subject: 1234
@@ -204,6 +239,22 @@ other body`,
204
239
},
205
240
},
206
241
}
242
+ if withNextReleaseBranch {
243
+ expected ["internal-release-branch.go1.5rc1" ] = []cherryPickedCommit {
244
+ {
245
+ changeID : "1234" ,
246
+ message : `[release-branch.go1.5] subject: 1234
247
+
248
+ body` ,
249
+ },
250
+ {
251
+ changeID : "5678" ,
252
+ message : `[release-branch.go1.5] subject: 5678
253
+
254
+ other body` ,
255
+ },
256
+ }
257
+ }
207
258
208
259
for branch , commits := range privGerrit .cherryPicks {
209
260
if ! slices .Equal (commits , expected [branch ]) {
0 commit comments