@@ -484,3 +484,54 @@ func TestDeleteItem(t *testing.T) {
484484 })
485485 }
486486}
487+
488+ func TestSanitizeGroupName (t * testing.T ) {
489+ r := & resolver.Service {}
490+ r .SetGroupNames (make (map [string ]string ))
491+
492+ tests := []struct {
493+ name string
494+ input string
495+ expected string
496+ }{
497+ {"empty_string" , "" , "core" },
498+ {"valid_group_name" , "validName" , "validName" },
499+ {"hyphen_to_underscore" , "group-name" , "group_name" },
500+ {"special_char_to_underscore" , "group@name" , "group_name" },
501+ {"invalid_start_with_prepend" , "!invalidStart" , "_invalidStart" },
502+ {"leading_underscore" , "_leadingUnderscore" , "_leadingUnderscore" },
503+ {"start_with_number" , "123startWithNumber" , "_123startWithNumber" },
504+ }
505+
506+ for _ , tt := range tests {
507+ t .Run (tt .name , func (t * testing.T ) {
508+ result := r .SanitizeGroupName (tt .input )
509+ assert .Equal (t , tt .expected , result )
510+ assert .Equal (t , tt .input , r .GetGroupName (result ), "The original group name should be stored correctly" )
511+ })
512+ }
513+ }
514+
515+ func TestGetOriginalGroupName (t * testing.T ) {
516+ r := & resolver.Service {}
517+ r .SetGroupNames (map [string ]string {
518+ "group1" : "originalGroup1" ,
519+ "group2" : "originalGroup2" ,
520+ })
521+
522+ tests := []struct {
523+ name string
524+ input string
525+ expected string
526+ }{
527+ {"existing_group" , "group1" , "originalGroup1" },
528+ {"non_existing_group" , "group3" , "group3" },
529+ }
530+
531+ for _ , tt := range tests {
532+ t .Run (tt .name , func (t * testing.T ) {
533+ result := r .GetOriginalGroupName (tt .input )
534+ assert .Equal (t , tt .expected , result )
535+ })
536+ }
537+ }
0 commit comments