feat(testutil): add GetRandomNameHyphenated (#17342)
This started coming up more often for me, so time for a test helper! --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package testutil
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
@@ -25,6 +26,14 @@ func GetRandomName(t testing.TB) string {
|
||||
return incSuffix(name, n.Add(1), maxNameLen)
|
||||
}
|
||||
|
||||
// GetRandomNameHyphenated is as GetRandomName but uses a hyphen "-" instead of
|
||||
// an underscore.
|
||||
func GetRandomNameHyphenated(t testing.TB) string {
|
||||
t.Helper()
|
||||
name := namesgenerator.GetRandomName(0)
|
||||
return strings.ReplaceAll(name, "_", "-")
|
||||
}
|
||||
|
||||
func incSuffix(s string, num int64, maxLen int) string {
|
||||
suffix := strconv.FormatInt(num, 10)
|
||||
if len(s)+len(suffix) <= maxLen {
|
||||
|
||||
Reference in New Issue
Block a user