Skip to content

Commit 24820e0

Browse files
vertex451lpgarzonr
andauthored
chore: better tests exports (#128)
On-behalf-of: @SAP [email protected] Signed-off-by: Artem Shcherbatiuk <[email protected]> Co-authored-by: Leidy Patricia Garzón Rodriguez <[email protected]>
1 parent bebbfca commit 24820e0

File tree

3 files changed

+64
-59
lines changed

3 files changed

+64
-59
lines changed

gateway/resolver/export_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package resolver
2+
3+
func (r *Service) GetOriginalGroupName(key string) string {
4+
return r.getOriginalGroupName(key)
5+
}
6+
7+
func (r *Service) GetGroupName(key string) string {
8+
return r.groupNames[key]
9+
}
10+
11+
func (r *Service) SetGroupNames(names map[string]string) {
12+
r.groupNames = names
13+
}

gateway/resolver/resolver_private_fields_test.go

Lines changed: 0 additions & 59 deletions
This file was deleted.

gateway/resolver/resolver_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)