@@ -463,65 +463,78 @@ func BenchmarkGetHugePageSizeImpl(b *testing.B) {
463
463
464
464
func TestGetHugePageSizeImpl (t * testing.T ) {
465
465
testCases := []struct {
466
+ doc string
466
467
input []string
467
468
output []string
468
469
isErr bool
469
470
}{
470
471
{
472
+ doc : "normal input" ,
471
473
input : []string {"hugepages-1048576kB" , "hugepages-2048kB" , "hugepages-32768kB" , "hugepages-64kB" },
472
474
output : []string {"1GB" , "2MB" , "32MB" , "64KB" },
473
475
},
474
476
{
477
+ doc : "empty input" ,
475
478
input : []string {},
476
479
output : []string {},
477
480
},
478
- { // not a number
481
+ {
482
+ doc : "not a number" ,
479
483
input : []string {"hugepages-akB" },
480
484
isErr : true ,
481
485
},
482
- { // no prefix (silently skipped)
486
+ {
487
+ doc : "no prefix (silently skipped)" ,
483
488
input : []string {"1024kB" },
484
489
},
485
- { // invalid prefix (silently skipped)
490
+ {
491
+ doc : "invalid prefix (silently skipped)" ,
486
492
input : []string {"whatever-1024kB" },
487
493
},
488
- { // invalid suffix
494
+ {
495
+ doc : "invalid suffix" ,
489
496
input : []string {"hugepages-1024gB" },
490
497
isErr : true ,
491
498
},
492
- { // no suffix
499
+ {
500
+ doc : "no suffix" ,
493
501
input : []string {"hugepages-1024" },
494
502
isErr : true ,
495
503
},
496
- { // mixed valid and invalid entries
504
+ {
505
+ doc : "mixed valid and invalid entries" ,
497
506
input : []string {"hugepages-4194304kB" , "hugepages-2048kB" , "hugepages-akB" , "hugepages-64kB" },
498
507
output : []string {"4GB" , "2MB" , "64KB" },
499
508
isErr : true ,
500
509
},
501
- { // mixed valid and invalid entries
510
+ {
511
+ doc : "more mixed valid and invalid entries" ,
502
512
input : []string {"hugepages-2048kB" , "hugepages-kB" , "hugepages-64kB" },
503
513
output : []string {"2MB" , "64KB" },
504
514
isErr : true ,
505
515
},
506
516
}
507
517
508
518
for _ , c := range testCases {
509
- output , err := getHugePageSizeFromFilenames (c .input )
510
- t .Log ("input:" , c .input , "; output:" , output , "; err:" , err )
511
- if err != nil {
512
- if ! c .isErr {
513
- t .Errorf ("input %v, expected nil, got error: %v" , c .input , err )
519
+ c := c
520
+ t .Run (c .doc , func (t * testing.T ) {
521
+ output , err := getHugePageSizeFromFilenames (c .input )
522
+ t .Log ("input:" , c .input , "; output:" , output , "; err:" , err )
523
+ if err != nil {
524
+ if ! c .isErr {
525
+ t .Errorf ("input %v, expected nil, got error: %v" , c .input , err )
526
+ }
527
+ // no more checks
528
+ return
514
529
}
515
- // no more checks
516
- continue
517
- }
518
- if c .isErr {
519
- t .Errorf ("input %v, expected error, got error: nil, output: %v" , c .input , output )
520
- }
521
- // check output
522
- if len (output ) != len (c .output ) || (len (output ) > 0 && ! reflect .DeepEqual (output , c .output )) {
523
- t .Errorf ("input %v, expected %v, got %v" , c .input , c .output , output )
524
- }
530
+ if c .isErr {
531
+ t .Errorf ("input %v, expected error, got error: nil, output: %v" , c .input , output )
532
+ }
533
+ // check output
534
+ if len (output ) != len (c .output ) || (len (output ) > 0 && ! reflect .DeepEqual (output , c .output )) {
535
+ t .Errorf ("input %v, expected %v, got %v" , c .input , c .output , output )
536
+ }
537
+ })
525
538
}
526
539
}
527
540
0 commit comments