Files
gatus/config/key/key_test.go
T

56 lines
1.2 KiB
Go
Raw Normal View History

2025-09-05 15:39:12 -04:00
package key
2021-01-27 18:25:37 -05:00
import "testing"
2025-09-05 15:39:12 -04:00
func TestConvertGroupAndNameToKey(t *testing.T) {
2021-01-27 18:25:37 -05:00
type Scenario struct {
GroupName string
2025-09-05 15:39:12 -04:00
Name string
2021-01-27 18:25:37 -05:00
ExpectedOutput string
}
scenarios := []Scenario{
{
GroupName: "Core",
2025-09-05 15:39:12 -04:00
Name: "Front End",
2021-01-27 18:25:37 -05:00
ExpectedOutput: "core_front-end",
},
{
GroupName: "Load balancers",
2025-09-05 15:39:12 -04:00
Name: "us-west-2",
2021-01-27 18:25:37 -05:00
ExpectedOutput: "load-balancers_us-west-2",
},
{
GroupName: "a/b test",
2025-09-05 15:39:12 -04:00
Name: "a",
2021-01-27 18:25:37 -05:00
ExpectedOutput: "a-b-test_a",
},
2025-09-05 15:39:12 -04:00
{
GroupName: "",
Name: "name",
ExpectedOutput: "_name",
},
{
GroupName: "API (v1)",
Name: "endpoint",
ExpectedOutput: "api-(v1)_endpoint",
},
{
GroupName: "website (admin)",
Name: "test",
ExpectedOutput: "website-(admin)_test",
},
{
GroupName: "search",
Name: "query&filter",
ExpectedOutput: "search_query-filter",
},
2021-01-27 18:25:37 -05:00
}
for _, scenario := range scenarios {
t.Run(scenario.ExpectedOutput, func(t *testing.T) {
2025-09-05 15:39:12 -04:00
output := ConvertGroupAndNameToKey(scenario.GroupName, scenario.Name)
2021-01-27 18:25:37 -05:00
if output != scenario.ExpectedOutput {
2021-10-23 16:47:12 -04:00
t.Errorf("expected '%s', got '%s'", scenario.ExpectedOutput, output)
2021-01-27 18:25:37 -05:00
}
})
}
}