@@ -30,7 +30,6 @@ import (
30
30
"github.com/cockroachdb/cockroach/pkg/roachprod/vm"
31
31
"github.com/cockroachdb/cockroach/pkg/roachprod/vm/gce"
32
32
"github.com/cockroachdb/cockroach/pkg/testutils/echotest"
33
- "github.com/stretchr/testify/assert"
34
33
"github.com/stretchr/testify/require"
35
34
)
36
35
@@ -128,6 +127,8 @@ func TestCreatePostRequest(t *testing.T) {
128
127
return failure {squashedErr : ref }
129
128
}
130
129
130
+ const testName = "github_test"
131
+
131
132
// TODO(radu): these tests should be converted to datadriven tests which
132
133
// output the full rendering of the github issue message along with the
133
134
// metadata.
@@ -143,6 +144,9 @@ func TestCreatePostRequest(t *testing.T) {
143
144
failures []failure
144
145
expectedPost bool
145
146
expectedLabels []string
147
+ expectedTeam string
148
+ expectedName string
149
+ expectedMessagePrefix string
146
150
expectedReleaseBlocker bool
147
151
expectedSkipTestFailure bool
148
152
expectedParams map [string ]string
@@ -154,6 +158,8 @@ func TestCreatePostRequest(t *testing.T) {
154
158
failures : []failure {createFailure (errors .New ("other" ))},
155
159
expectedPost : true ,
156
160
expectedLabels : []string {"C-test-failure" },
161
+ expectedTeam : "@cockroachdb/unowned" ,
162
+ expectedName : testName ,
157
163
expectedParams : prefixAll (map [string ]string {
158
164
"cloud" : "gce" ,
159
165
"encrypted" : "false" ,
@@ -171,9 +177,14 @@ func TestCreatePostRequest(t *testing.T) {
171
177
localSSD : true ,
172
178
metamorphicBuild : true ,
173
179
arch : vm .ArchARM64 ,
174
- failures : []failure {createFailure (errClusterProvisioningFailed )},
175
- expectedPost : true ,
176
- expectedLabels : []string {"T-testeng" , "X-infra-flake" },
180
+ failures : []failure {
181
+ createFailure (errClusterProvisioningFailed (errors .New ("gcloud error" ))),
182
+ },
183
+ expectedPost : true ,
184
+ expectedLabels : []string {"T-testeng" , "X-infra-flake" },
185
+ expectedTeam : "@cockroachdb/test-eng" ,
186
+ expectedName : "cluster_creation" ,
187
+ expectedMessagePrefix : testName + " failed" ,
177
188
expectedParams : prefixAll (map [string ]string {
178
189
"cloud" : "gce" ,
179
190
"encrypted" : "false" ,
@@ -195,6 +206,9 @@ func TestCreatePostRequest(t *testing.T) {
195
206
failures : []failure {createFailure (rperrors .ErrSSH255 )},
196
207
expectedPost : true ,
197
208
expectedLabels : []string {"T-testeng" , "X-infra-flake" },
209
+ expectedTeam : "@cockroachdb/test-eng" ,
210
+ expectedName : "ssh_problem" ,
211
+ expectedMessagePrefix : testName + " failed" ,
198
212
expectedParams : prefixAll (map [string ]string {
199
213
"cloud" : "gce" ,
200
214
"ssd" : "0" ,
@@ -210,25 +224,24 @@ func TestCreatePostRequest(t *testing.T) {
210
224
failures : []failure {createFailure (errors .New ("other" ))},
211
225
expectedLabels : []string {"C-test-failure" },
212
226
},
213
- // 5. Error during post test assertions
214
- {
215
- nonReleaseBlocker : true ,
216
- failures : []failure {createFailure (errDuringPostAssertions )},
217
- expectedLabels : []string {"C-test-failure" },
218
- },
219
- // 6. Error during dns operation.
227
+ // 5. Error during dns operation.
220
228
{
221
- nonReleaseBlocker : true ,
222
- failures : []failure {createFailure (gce .ErrDNSOperation )},
223
- expectedPost : true ,
224
- expectedLabels : []string {"T-testeng" , "X-infra-flake" },
229
+ nonReleaseBlocker : true ,
230
+ failures : []failure {createFailure (gce .ErrDNSOperation )},
231
+ expectedPost : true ,
232
+ expectedLabels : []string {"T-testeng" , "X-infra-flake" },
233
+ expectedTeam : "@cockroachdb/test-eng" ,
234
+ expectedName : "dns_problem" ,
235
+ expectedMessagePrefix : testName + " failed" ,
225
236
},
226
- // 7 . Assert that extra labels in the test spec are added to the issue.
237
+ // 6 . Assert that extra labels in the test spec are added to the issue.
227
238
{
228
239
extraLabels : []string {"foo-label" },
229
240
failures : []failure {createFailure (errors .New ("other" ))},
230
241
expectedPost : true ,
231
242
expectedLabels : []string {"C-test-failure" , "release-blocker" , "foo-label" },
243
+ expectedTeam : "@cockroachdb/unowned" ,
244
+ expectedName : testName ,
232
245
expectedParams : prefixAll (map [string ]string {
233
246
"cloud" : "gce" ,
234
247
"encrypted" : "false" ,
@@ -241,13 +254,15 @@ func TestCreatePostRequest(t *testing.T) {
241
254
"coverageBuild" : "false" ,
242
255
}),
243
256
},
244
- // 8 . Verify that release-blocker label is not applied on metamorphic builds
257
+ // 7 . Verify that release-blocker label is not applied on metamorphic builds
245
258
// (for now).
246
259
{
247
260
metamorphicBuild : true ,
248
261
failures : []failure {createFailure (errors .New ("other" ))},
249
262
expectedPost : true ,
250
263
expectedLabels : []string {"C-test-failure" , "B-metamorphic-enabled" },
264
+ expectedTeam : "@cockroachdb/unowned" ,
265
+ expectedName : testName ,
251
266
expectedParams : prefixAll (map [string ]string {
252
267
"cloud" : "gce" ,
253
268
"encrypted" : "false" ,
@@ -260,13 +275,15 @@ func TestCreatePostRequest(t *testing.T) {
260
275
"coverageBuild" : "false" ,
261
276
}),
262
277
},
263
- // 9 . Verify that release-blocker label is not applied on coverage builds (for
278
+ // 8 . Verify that release-blocker label is not applied on coverage builds (for
264
279
// now).
265
280
{
266
281
extraLabels : []string {"foo-label" },
267
282
coverageBuild : true ,
268
283
failures : []failure {createFailure (errors .New ("other" ))},
269
284
expectedPost : true ,
285
+ expectedTeam : "@cockroachdb/unowned" ,
286
+ expectedName : testName ,
270
287
expectedLabels : []string {"C-test-failure" , "B-coverage-enabled" , "foo-label" },
271
288
expectedParams : prefixAll (map [string ]string {
272
289
"cloud" : "gce" ,
@@ -280,29 +297,40 @@ func TestCreatePostRequest(t *testing.T) {
280
297
"coverageBuild" : "true" ,
281
298
}),
282
299
},
283
- // 10 . Verify preemption failure are routed to test-eng and marked as infra-flake,
300
+ // 9 . Verify preemption failure are routed to test-eng and marked as infra-flake,
284
301
// even if the first failure is another handled error.
285
302
{
286
- nonReleaseBlocker : true ,
287
- failures : []failure {createFailure (gce .ErrDNSOperation ), createFailure (errVMPreemption )},
288
- expectedPost : true ,
289
- expectedLabels : []string {"T-testeng" , "X-infra-flake" },
303
+ nonReleaseBlocker : true ,
304
+ failures : []failure {createFailure (gce .ErrDNSOperation ), createFailure (vmPreemptionError ("my_VM" ))},
305
+ expectedPost : true ,
306
+ expectedName : "vm_preemption" ,
307
+ expectedTeam : "@cockroachdb/test-eng" ,
308
+ expectedMessagePrefix : testName + " failed" ,
309
+ expectedLabels : []string {"T-testeng" , "X-infra-flake" },
290
310
},
291
- // 11 . Verify preemption failure are routed to test-eng and marked as infra-flake, when the
311
+ // 10 . Verify preemption failure are routed to test-eng and marked as infra-flake, when the
292
312
// first failure is a non-handled error.
293
313
{
294
- nonReleaseBlocker : true ,
295
- failures : []failure {createFailure (errors .New ("random" )), createFailure (errVMPreemption )},
296
- expectedPost : true ,
297
- expectedLabels : []string {"T-testeng" , "X-infra-flake" },
314
+ nonReleaseBlocker : true ,
315
+ failures : []failure {createFailure (errors .New ("random" )), createFailure (vmPreemptionError ("my_VM" ))},
316
+ expectedPost : true ,
317
+ expectedTeam : "@cockroachdb/test-eng" ,
318
+ expectedName : "vm_preemption" ,
319
+ expectedMessagePrefix : testName + " failed" ,
320
+ expectedLabels : []string {"T-testeng" , "X-infra-flake" },
298
321
},
299
- // 12 . Verify preemption failure are routed to test-eng and marked as infra-flake, when the only error is
322
+ // 11 . Verify preemption failure are routed to test-eng and marked as infra-flake, when the only error is
300
323
// preemption failure
301
324
{
302
325
nonReleaseBlocker : true ,
303
- failures : []failure {{errors : []error {errVMPreemption }}},
304
- expectedPost : true ,
305
- expectedLabels : []string {"T-testeng" , "X-infra-flake" },
326
+ failures : []failure {
327
+ {errors : []error {vmPreemptionError ("my_VM" )}},
328
+ },
329
+ expectedPost : true ,
330
+ expectedTeam : "@cockroachdb/test-eng" ,
331
+ expectedName : "vm_preemption" ,
332
+ expectedMessagePrefix : testName + " failed" ,
333
+ expectedLabels : []string {"T-testeng" , "X-infra-flake" },
306
334
},
307
335
}
308
336
@@ -312,7 +340,7 @@ func TestCreatePostRequest(t *testing.T) {
312
340
clusterSpec := reg .MakeClusterSpec (1 , spec .Arch (testCase .arch ))
313
341
314
342
testSpec := & registry.TestSpec {
315
- Name : "github_test" ,
343
+ Name : testName ,
316
344
Owner : OwnerUnitTest ,
317
345
Cluster : clusterSpec ,
318
346
NonReleaseBlocker : testCase .nonReleaseBlocker ,
@@ -350,57 +378,35 @@ func TestCreatePostRequest(t *testing.T) {
350
378
teamLoader : teamLoadFn ,
351
379
}
352
380
381
+ req , err := github .createPostRequest (
382
+ testName , ti .start , ti .end , testSpec , testCase .failures ,
383
+ testCase .message , testCase .metamorphicBuild , testCase .coverageBuild ,
384
+ )
353
385
if testCase .loadTeamsFailed {
354
386
// Assert that if TEAMS.yaml cannot be loaded then function errors.
355
- _ , err := github .createPostRequest ("github_test" , ti .start , ti .end , testSpec , testCase .failures , testCase .message , testCase .metamorphicBuild , testCase .coverageBuild )
356
- assert .Error (t , err , "Expected an error in createPostRequest when loading teams fails, but got nil" )
357
- } else {
358
- req , err := github .createPostRequest ("github_test" , ti .start , ti .end , testSpec , testCase .failures , testCase .message , testCase .metamorphicBuild , testCase .coverageBuild )
359
- assert .NoError (t , err , "Expected no error in createPostRequest" )
360
-
361
- r := & issues.Renderer {}
362
- req .HelpCommand (r )
363
- file := fmt .Sprintf ("help_command_createpost_%d.txt" , idx + 1 )
364
- echotest .Require (t , r .String (), filepath .Join ("testdata" , file ))
365
-
366
- if testCase .expectedParams != nil {
367
- require .Equal (t , testCase .expectedParams , req .ExtraParams )
368
- }
369
-
370
- expLabels := append ([]string {"O-roachtest" }, testCase .expectedLabels ... )
371
- sort .Strings (expLabels )
372
- labels := append ([]string {}, req .Labels ... )
373
- sort .Strings (expLabels )
374
- sort .Strings (labels )
375
- require .Equal (t , expLabels , labels )
376
-
377
- expectedTeam := "@cockroachdb/unowned"
378
- expectedName := "github_test"
379
- expectedMessagePrefix := ""
380
- if failuresContainsError (testCase .failures , errVMPreemption ) {
381
- expectedTeam = "@cockroachdb/test-eng"
382
- expectedName = "vm_preemption"
383
- expectedMessagePrefix = "test github_test failed due to "
384
- } else if errors .Is (testCase .failures [0 ].squashedErr , gce .ErrDNSOperation ) {
385
- expectedTeam = "@cockroachdb/test-eng"
386
- expectedName = "dns_problem"
387
- expectedMessagePrefix = "test github_test failed due to "
388
- } else if errors .Is (testCase .failures [0 ].squashedErr , errClusterProvisioningFailed ) {
389
- expectedTeam = "@cockroachdb/test-eng"
390
- expectedName = "cluster_creation"
391
- expectedMessagePrefix = "test github_test was skipped due to "
392
- } else if errors .Is (testCase .failures [0 ].squashedErr , rperrors .ErrSSH255 ) {
393
- expectedTeam = "@cockroachdb/test-eng"
394
- expectedName = "ssh_problem"
395
- expectedMessagePrefix = "test github_test failed due to "
396
- } else if errors .Is (testCase .failures [0 ].squashedErr , errDuringPostAssertions ) {
397
- expectedMessagePrefix = "test github_test failed during post test assertions (see test-post-assertions.log) due to "
398
- }
399
-
400
- require .Contains (t , req .MentionOnCreate , expectedTeam )
401
- require .Equal (t , expectedName , req .TestName )
402
- require .True (t , strings .HasPrefix (req .Message , expectedMessagePrefix ), req .Message )
387
+ require .Error (t , err )
388
+ return
403
389
}
390
+
391
+ require .NoError (t , err )
392
+
393
+ r := & issues.Renderer {}
394
+ req .HelpCommand (r )
395
+ file := fmt .Sprintf ("help_command_createpost_%d.txt" , idx + 1 )
396
+ echotest .Require (t , r .String (), filepath .Join ("testdata" , file ))
397
+
398
+ if testCase .expectedParams != nil {
399
+ require .Equal (t , testCase .expectedParams , req .ExtraParams )
400
+ }
401
+
402
+ expLabels := append ([]string {"O-roachtest" }, testCase .expectedLabels ... )
403
+ sort .Strings (expLabels )
404
+ sort .Strings (req .Labels )
405
+ require .Equal (t , expLabels , req .Labels )
406
+
407
+ require .Contains (t , req .MentionOnCreate , testCase .expectedTeam )
408
+ require .Equal (t , testCase .expectedName , req .TestName )
409
+ require .Contains (t , req .Message , testCase .expectedMessagePrefix )
404
410
})
405
411
}
406
412
}
0 commit comments