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",
|
|
|
|
|
},
|
2025-10-16 16:47:11 -04:00
|
|
|
{
|
|
|
|
|
GroupName: "API (v1)",
|
|
|
|
|
Name: "endpoint",
|
2025-10-20 13:50:02 -04:00
|
|
|
ExpectedOutput: "api-(v1)_endpoint",
|
2025-10-16 16:47:11 -04:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
GroupName: "website (admin)",
|
|
|
|
|
Name: "test",
|
2025-10-20 13:50:02 -04:00
|
|
|
ExpectedOutput: "website-(admin)_test",
|
2025-10-16 16:47:11 -04:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|