|
6 | 6 | "testing"
|
7 | 7 | "time"
|
8 | 8 |
|
9 |
| - "github.com/jstemmer/go-junit-report/v2/gtr" |
10 |
| - |
11 | 9 | "github.com/google/go-cmp/cmp"
|
12 | 10 | )
|
13 | 11 |
|
@@ -215,220 +213,3 @@ func TestParseLine(t *testing.T) {
|
215 | 213 | })
|
216 | 214 | }
|
217 | 215 | }
|
218 |
| - |
219 |
| -func TestReport(t *testing.T) { |
220 |
| - events := []Event{ |
221 |
| - {Type: "run_test", Name: "TestOne"}, |
222 |
| - {Type: "output", Data: "\tHello"}, |
223 |
| - {Type: "end_test", Name: "TestOne", Result: "PASS", Duration: 1 * time.Millisecond}, |
224 |
| - {Type: "status", Result: "PASS"}, |
225 |
| - {Type: "run_test", Name: "TestSkip"}, |
226 |
| - {Type: "end_test", Name: "TestSkip", Result: "SKIP", Duration: 1 * time.Millisecond}, |
227 |
| - {Type: "summary", Result: "ok", Name: "package/name", Duration: 1 * time.Millisecond}, |
228 |
| - {Type: "run_test", Name: "TestOne"}, |
229 |
| - {Type: "output", Data: "\tfile_test.go:10: error"}, |
230 |
| - {Type: "end_test", Name: "TestOne", Result: "FAIL", Duration: 1 * time.Millisecond}, |
231 |
| - {Type: "status", Result: "FAIL"}, |
232 |
| - {Type: "summary", Result: "FAIL", Name: "package/name2", Duration: 1 * time.Millisecond}, |
233 |
| - {Type: "output", Data: "goarch: amd64"}, |
234 |
| - {Type: "run_benchmark", Name: "BenchmarkOne"}, |
235 |
| - {Type: "benchmark", Name: "BenchmarkOne", NsPerOp: 100}, |
236 |
| - {Type: "end_benchmark", Name: "BenchmarkOne", Result: "BENCH"}, |
237 |
| - {Type: "run_benchmark", Name: "BenchmarkTwo"}, |
238 |
| - {Type: "benchmark", Name: "BenchmarkTwo"}, |
239 |
| - {Type: "end_benchmark", Name: "BenchmarkTwo", Result: "FAIL"}, |
240 |
| - {Type: "status", Result: "PASS"}, |
241 |
| - {Type: "summary", Result: "ok", Name: "package/name3", Duration: 1234 * time.Millisecond}, |
242 |
| - {Type: "build_output", Name: "package/failing1"}, |
243 |
| - {Type: "output", Data: "error message"}, |
244 |
| - {Type: "summary", Result: "FAIL", Name: "package/failing1", Data: "[build failed]"}, |
245 |
| - } |
246 |
| - want := gtr.Report{ |
247 |
| - Packages: []gtr.Package{ |
248 |
| - { |
249 |
| - Name: "package/name", |
250 |
| - Duration: 1 * time.Millisecond, |
251 |
| - Timestamp: testTimestamp, |
252 |
| - Tests: []gtr.Test{ |
253 |
| - { |
254 |
| - ID: 1, |
255 |
| - Name: "TestOne", |
256 |
| - Duration: 1 * time.Millisecond, |
257 |
| - Result: gtr.Pass, |
258 |
| - Output: []string{ |
259 |
| - "\tHello", // TODO: strip tabs? |
260 |
| - }, |
261 |
| - Data: map[string]interface{}{}, |
262 |
| - }, |
263 |
| - { |
264 |
| - ID: 2, |
265 |
| - Name: "TestSkip", |
266 |
| - Duration: 1 * time.Millisecond, |
267 |
| - Result: gtr.Skip, |
268 |
| - Data: map[string]interface{}{}, |
269 |
| - }, |
270 |
| - }, |
271 |
| - }, |
272 |
| - { |
273 |
| - Name: "package/name2", |
274 |
| - Duration: 1 * time.Millisecond, |
275 |
| - Timestamp: testTimestamp, |
276 |
| - Tests: []gtr.Test{ |
277 |
| - { |
278 |
| - ID: 3, |
279 |
| - Name: "TestOne", |
280 |
| - Duration: 1 * time.Millisecond, |
281 |
| - Result: gtr.Fail, |
282 |
| - Output: []string{ |
283 |
| - "\tfile_test.go:10: error", |
284 |
| - }, |
285 |
| - Data: map[string]interface{}{}, |
286 |
| - }, |
287 |
| - }, |
288 |
| - }, |
289 |
| - { |
290 |
| - Name: "package/name3", |
291 |
| - Duration: 1234 * time.Millisecond, |
292 |
| - Timestamp: testTimestamp, |
293 |
| - Tests: []gtr.Test{ |
294 |
| - { |
295 |
| - ID: 4, |
296 |
| - Name: "BenchmarkOne", |
297 |
| - Result: gtr.Pass, |
298 |
| - Data: map[string]interface{}{key: Benchmark{NsPerOp: 100}}, |
299 |
| - }, |
300 |
| - { |
301 |
| - ID: 5, |
302 |
| - Name: "BenchmarkTwo", |
303 |
| - Result: gtr.Fail, |
304 |
| - Data: map[string]interface{}{}, |
305 |
| - }, |
306 |
| - }, |
307 |
| - Output: []string{"goarch: amd64"}, |
308 |
| - }, |
309 |
| - { |
310 |
| - Name: "package/failing1", |
311 |
| - Timestamp: testTimestamp, |
312 |
| - BuildError: gtr.Error{ |
313 |
| - ID: 6, |
314 |
| - Name: "package/failing1", |
315 |
| - Cause: "[build failed]", |
316 |
| - Output: []string{"error message"}, |
317 |
| - }, |
318 |
| - }, |
319 |
| - }, |
320 |
| - } |
321 |
| - |
322 |
| - parser := NewParser(TimestampFunc(testTimestampFunc)) |
323 |
| - got := parser.report(events) |
324 |
| - if diff := cmp.Diff(want, got); diff != "" { |
325 |
| - t.Errorf("FromEvents report incorrect, diff (-want, +got):\n%v", diff) |
326 |
| - } |
327 |
| -} |
328 |
| - |
329 |
| -func TestSubtestModes(t *testing.T) { |
330 |
| - events := []Event{ |
331 |
| - {Type: "run_test", Name: "TestParent"}, |
332 |
| - {Type: "output", Data: "TestParent before"}, |
333 |
| - {Type: "run_test", Name: "TestParent/Subtest#1"}, |
334 |
| - {Type: "output", Data: "Subtest#1 output"}, |
335 |
| - {Type: "run_test", Name: "TestParent/Subtest#2"}, |
336 |
| - {Type: "output", Data: "Subtest#2 output"}, |
337 |
| - {Type: "cont_test", Name: "TestParent"}, |
338 |
| - {Type: "output", Data: "TestParent after"}, |
339 |
| - {Type: "end_test", Name: "TestParent", Result: "PASS", Duration: 1 * time.Millisecond}, |
340 |
| - {Type: "end_test", Name: "TestParent/Subtest#1", Result: "FAIL", Duration: 2 * time.Millisecond}, |
341 |
| - {Type: "end_test", Name: "TestParent/Subtest#2", Result: "PASS", Duration: 3 * time.Millisecond}, |
342 |
| - {Type: "output", Data: "output"}, |
343 |
| - {Type: "summary", Result: "FAIL", Name: "package/name", Duration: 1 * time.Millisecond}, |
344 |
| - } |
345 |
| - |
346 |
| - tests := []struct { |
347 |
| - name string |
348 |
| - mode SubtestMode |
349 |
| - want gtr.Report |
350 |
| - }{ |
351 |
| - { |
352 |
| - name: "ignore subtest parent results", |
353 |
| - mode: IgnoreParentResults, |
354 |
| - want: gtr.Report{ |
355 |
| - Packages: []gtr.Package{ |
356 |
| - { |
357 |
| - Name: "package/name", |
358 |
| - Duration: 1 * time.Millisecond, |
359 |
| - Timestamp: testTimestamp, |
360 |
| - Tests: []gtr.Test{ |
361 |
| - { |
362 |
| - ID: 1, |
363 |
| - Name: "TestParent", |
364 |
| - Duration: 1 * time.Millisecond, |
365 |
| - Result: gtr.Pass, |
366 |
| - Output: []string{"TestParent before", "TestParent after"}, |
367 |
| - Data: map[string]interface{}{}, |
368 |
| - }, |
369 |
| - { |
370 |
| - ID: 2, |
371 |
| - Name: "TestParent/Subtest#1", |
372 |
| - Duration: 2 * time.Millisecond, |
373 |
| - Result: gtr.Fail, |
374 |
| - Output: []string{"Subtest#1 output"}, |
375 |
| - Data: map[string]interface{}{}, |
376 |
| - }, |
377 |
| - { |
378 |
| - ID: 3, |
379 |
| - Name: "TestParent/Subtest#2", |
380 |
| - Duration: 3 * time.Millisecond, |
381 |
| - Result: gtr.Pass, |
382 |
| - Output: []string{"Subtest#2 output"}, |
383 |
| - Data: map[string]interface{}{}, |
384 |
| - }, |
385 |
| - }, |
386 |
| - Output: []string{"output"}, |
387 |
| - }, |
388 |
| - }, |
389 |
| - }, |
390 |
| - }, |
391 |
| - { |
392 |
| - name: "exclude subtest parents", |
393 |
| - mode: ExcludeParents, |
394 |
| - want: gtr.Report{ |
395 |
| - Packages: []gtr.Package{ |
396 |
| - { |
397 |
| - Name: "package/name", |
398 |
| - Duration: 1 * time.Millisecond, |
399 |
| - Timestamp: testTimestamp, |
400 |
| - Tests: []gtr.Test{ |
401 |
| - { |
402 |
| - ID: 2, |
403 |
| - Name: "TestParent/Subtest#1", |
404 |
| - Duration: 2 * time.Millisecond, |
405 |
| - Result: gtr.Fail, |
406 |
| - Output: []string{"Subtest#1 output"}, |
407 |
| - Data: map[string]interface{}{}, |
408 |
| - }, |
409 |
| - { |
410 |
| - ID: 3, |
411 |
| - Name: "TestParent/Subtest#2", |
412 |
| - Duration: 3 * time.Millisecond, |
413 |
| - Result: gtr.Pass, |
414 |
| - Output: []string{"Subtest#2 output"}, |
415 |
| - Data: map[string]interface{}{}, |
416 |
| - }, |
417 |
| - }, |
418 |
| - Output: []string{"TestParent before", "TestParent after", "output"}, |
419 |
| - }, |
420 |
| - }, |
421 |
| - }, |
422 |
| - }, |
423 |
| - } |
424 |
| - |
425 |
| - for _, test := range tests { |
426 |
| - t.Run(test.name, func(t *testing.T) { |
427 |
| - parser := NewParser(TimestampFunc(testTimestampFunc), SetSubtestMode(test.mode)) |
428 |
| - got := parser.report(events) |
429 |
| - if diff := cmp.Diff(test.want, got); diff != "" { |
430 |
| - t.Errorf("Invalid report created from events, diff (-want, +got):\n%v", diff) |
431 |
| - } |
432 |
| - }) |
433 |
| - } |
434 |
| -} |
0 commit comments