@@ -36,6 +36,34 @@ func TestListEvaluationHistoryFilters(t *testing.T) {
36
36
ere1 := createRandomEvaluationRuleEntity (t , riID1 , repo1 .ID )
37
37
es1 := createRandomEvaluationStatus (t , ere1 )
38
38
39
+ // Evaluations for this profile should not show up in the
40
+ // results.
41
+ ruleType2 := createRandomRuleType (t , proj .ID )
42
+ profile2 := createRandomProfile (t , proj .ID , []string {"label2" })
43
+ fmt .Println (profile2 )
44
+ riID2 := createRandomRuleInstance (
45
+ t ,
46
+ proj .ID ,
47
+ profile2 .ID ,
48
+ ruleType2 .ID ,
49
+ )
50
+ ere2 := createRandomEvaluationRuleEntity (t , riID2 , repo1 .ID )
51
+ es2 := createRandomEvaluationStatus (t , ere2 )
52
+
53
+ // Evaluations for this profile should not show up in the
54
+ // results.
55
+ ruleType3 := createRandomRuleType (t , proj .ID )
56
+ profile3 := createRandomProfile (t , proj .ID , []string {"label3" })
57
+ fmt .Println (profile3 )
58
+ riID3 := createRandomRuleInstance (
59
+ t ,
60
+ proj .ID ,
61
+ profile3 .ID ,
62
+ ruleType3 .ID ,
63
+ )
64
+ ere3 := createRandomEvaluationRuleEntity (t , riID3 , repo1 .ID )
65
+ es3 := createRandomEvaluationStatus (t , ere3 )
66
+
39
67
tests := []struct {
40
68
name string
41
69
params ListEvaluationHistoryParams
@@ -392,6 +420,193 @@ func TestListEvaluationHistoryFilters(t *testing.T) {
392
420
},
393
421
},
394
422
423
+ // profile labels filter
424
+ {
425
+ name : "profile labels filter missing" ,
426
+ params : ListEvaluationHistoryParams {
427
+ Next : sql.NullTime {
428
+ Time : time .UnixMicro (999999999999999999 ).UTC (),
429
+ Valid : true ,
430
+ },
431
+ Projectid : proj .ID ,
432
+ Size : 5 ,
433
+ },
434
+ checkf : func (t * testing.T , rows []ListEvaluationHistoryRow ) {
435
+ t .Helper ()
436
+ require .Len (t , rows , 1 )
437
+ row := rows [0 ]
438
+ require .Equal (t , es1 , row .EvaluationID )
439
+ require .Equal (t , EntitiesRepository , row .EntityType )
440
+ require .Equal (t , repo1 .ID , row .EntityID )
441
+ require .Empty (t , row .ProfileLabels )
442
+ },
443
+ },
444
+ {
445
+ name : "profile labels filter include" ,
446
+ params : ListEvaluationHistoryParams {
447
+ Next : sql.NullTime {
448
+ Time : time .UnixMicro (999999999999999999 ).UTC (),
449
+ Valid : true ,
450
+ },
451
+ Labels : []string {"nonexisting" },
452
+ Projectid : proj .ID ,
453
+ Size : 5 ,
454
+ },
455
+ checkf : func (t * testing.T , rows []ListEvaluationHistoryRow ) {
456
+ t .Helper ()
457
+ require .Len (t , rows , 0 )
458
+ },
459
+ },
460
+ {
461
+ name : "profile labels filter include match label2" ,
462
+ params : ListEvaluationHistoryParams {
463
+ Next : sql.NullTime {
464
+ Time : time .UnixMicro (999999999999999999 ).UTC (),
465
+ Valid : true ,
466
+ },
467
+ Labels : []string {"label2" },
468
+ Projectid : proj .ID ,
469
+ Size : 5 ,
470
+ },
471
+ checkf : func (t * testing.T , rows []ListEvaluationHistoryRow ) {
472
+ t .Helper ()
473
+ require .Len (t , rows , 1 )
474
+ row := rows [0 ]
475
+ require .Equal (t , es2 , row .EvaluationID )
476
+ require .Equal (t , EntitiesRepository , row .EntityType )
477
+ require .Equal (t , repo1 .ID , row .EntityID )
478
+ require .Equal (t , profile2 .Labels , row .ProfileLabels )
479
+ },
480
+ },
481
+ {
482
+ name : "profile labels filter include match label3" ,
483
+ params : ListEvaluationHistoryParams {
484
+ Next : sql.NullTime {
485
+ Time : time .UnixMicro (999999999999999999 ).UTC (),
486
+ Valid : true ,
487
+ },
488
+ Labels : []string {"label3" },
489
+ Projectid : proj .ID ,
490
+ Size : 5 ,
491
+ },
492
+ checkf : func (t * testing.T , rows []ListEvaluationHistoryRow ) {
493
+ t .Helper ()
494
+ require .Len (t , rows , 1 )
495
+ row := rows [0 ]
496
+ require .Equal (t , es3 , row .EvaluationID )
497
+ require .Equal (t , EntitiesRepository , row .EntityType )
498
+ require .Equal (t , repo1 .ID , row .EntityID )
499
+ require .Equal (t , profile3 .Labels , row .ProfileLabels )
500
+ },
501
+ },
502
+ {
503
+ name : "profile labels filter match *" ,
504
+ params : ListEvaluationHistoryParams {
505
+ Next : sql.NullTime {
506
+ Time : time .UnixMicro (999999999999999999 ).UTC (),
507
+ Valid : true ,
508
+ },
509
+ Labels : []string {"*" },
510
+ Projectid : proj .ID ,
511
+ Size : 5 ,
512
+ },
513
+ checkf : func (t * testing.T , rows []ListEvaluationHistoryRow ) {
514
+ t .Helper ()
515
+ require .Len (t , rows , 3 )
516
+
517
+ row := rows [0 ]
518
+ require .Equal (t , es3 , row .EvaluationID )
519
+ require .Equal (t , EntitiesRepository , row .EntityType )
520
+ require .Equal (t , repo1 .ID , row .EntityID )
521
+ require .Equal (t , profile3 .Labels , row .ProfileLabels )
522
+
523
+ row = rows [1 ]
524
+ require .Equal (t , es2 , row .EvaluationID )
525
+ require .Equal (t , EntitiesRepository , row .EntityType )
526
+ require .Equal (t , repo1 .ID , row .EntityID )
527
+ require .Equal (t , profile2 .Labels , row .ProfileLabels )
528
+
529
+ row = rows [2 ]
530
+ require .Equal (t , es1 , row .EvaluationID )
531
+ require .Equal (t , EntitiesRepository , row .EntityType )
532
+ require .Equal (t , repo1 .ID , row .EntityID )
533
+ require .Equal (t , profile1 .Labels , row .ProfileLabels )
534
+ },
535
+ },
536
+ {
537
+ name : "profile labels filter exclude label2" ,
538
+ params : ListEvaluationHistoryParams {
539
+ Next : sql.NullTime {
540
+ Time : time .UnixMicro (999999999999999999 ).UTC (),
541
+ Valid : true ,
542
+ },
543
+ Notlabels : []string {"label2" },
544
+ Projectid : proj .ID ,
545
+ Size : 5 ,
546
+ },
547
+ checkf : func (t * testing.T , rows []ListEvaluationHistoryRow ) {
548
+ t .Helper ()
549
+ require .Len (t , rows , 1 )
550
+
551
+ row := rows [0 ]
552
+ require .Equal (t , es1 , row .EvaluationID )
553
+ require .Equal (t , EntitiesRepository , row .EntityType )
554
+ require .Equal (t , repo1 .ID , row .EntityID )
555
+ require .Equal (t , profile1 .Labels , row .ProfileLabels )
556
+ },
557
+ },
558
+ {
559
+ name : "profile labels filter exclude label3" ,
560
+ params : ListEvaluationHistoryParams {
561
+ Next : sql.NullTime {
562
+ Time : time .UnixMicro (999999999999999999 ).UTC (),
563
+ Valid : true ,
564
+ },
565
+ Notlabels : []string {"label3" },
566
+ Projectid : proj .ID ,
567
+ Size : 5 ,
568
+ },
569
+ checkf : func (t * testing.T , rows []ListEvaluationHistoryRow ) {
570
+ t .Helper ()
571
+ require .Len (t , rows , 1 )
572
+
573
+ row := rows [0 ]
574
+ require .Equal (t , es1 , row .EvaluationID )
575
+ require .Equal (t , EntitiesRepository , row .EntityType )
576
+ require .Equal (t , repo1 .ID , row .EntityID )
577
+ require .Equal (t , profile1 .Labels , row .ProfileLabels )
578
+ },
579
+ },
580
+ {
581
+ name : "profile labels filter include * exclude label2" ,
582
+ params : ListEvaluationHistoryParams {
583
+ Next : sql.NullTime {
584
+ Time : time .UnixMicro (999999999999999999 ).UTC (),
585
+ Valid : true ,
586
+ },
587
+ Labels : []string {"*" },
588
+ Notlabels : []string {"label3" },
589
+ Projectid : proj .ID ,
590
+ Size : 5 ,
591
+ },
592
+ checkf : func (t * testing.T , rows []ListEvaluationHistoryRow ) {
593
+ t .Helper ()
594
+ require .Len (t , rows , 2 )
595
+
596
+ row := rows [0 ]
597
+ require .Equal (t , es2 , row .EvaluationID )
598
+ require .Equal (t , EntitiesRepository , row .EntityType )
599
+ require .Equal (t , repo1 .ID , row .EntityID )
600
+ require .Equal (t , profile2 .Labels , row .ProfileLabels )
601
+
602
+ row = rows [1 ]
603
+ require .Equal (t , es1 , row .EvaluationID )
604
+ require .Equal (t , EntitiesRepository , row .EntityType )
605
+ require .Equal (t , repo1 .ID , row .EntityID )
606
+ require .Equal (t , profile1 .Labels , row .ProfileLabels )
607
+ },
608
+ },
609
+
395
610
// time range filter
396
611
{
397
612
name : "time range filter from +1h" ,
@@ -671,6 +886,7 @@ func TestGetEvaluationHistory(t *testing.T) {
671
886
for i := 0 ; i < 10 ; i ++ {
672
887
repos = append (repos , createRandomRepository (t , proj .ID , prov ))
673
888
}
889
+
674
890
ruleType1 := createRandomRuleType (t , proj .ID )
675
891
profile1 := createRandomProfile (t , proj .ID , []string {})
676
892
riID1 := createRandomRuleInstance (
0 commit comments