Files
0d2783075a test(e2e): add isolation by ensuring unique name (cherry-pick #25724 for 3.3) (#26287)
Signed-off-by: Alexandre Gaudreault <[email protected]>
Signed-off-by: Kanika Rana <[email protected]>
Signed-off-by: Kanika Rana <[email protected]>
Signed-off-by: Oliver Gondža <[email protected]>
Co-authored-by: Alexandre Gaudreault <[email protected]>
Co-authored-by: Oliver Gondža <[email protected]>
2026-02-12 14:31:21 +02:00

40 lines
990 B
Go

package fixture
import (
"regexp"
"strings"
"testing"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
)
var (
matchFirstCap = regexp.MustCompile("(.)([A-Z][a-z]+)")
matchAllCap = regexp.MustCompile("([a-z0-9])([A-Z])")
)
// returns dns friends string which is no longer than 63 characters and has specified postfix at the end
func DnsFriendly(str string, postfix string) string { //nolint:revive //FIXME(var-naming)
str = matchFirstCap.ReplaceAllString(str, "${1}-${2}")
str = matchAllCap.ReplaceAllString(str, "${1}-${2}")
str = strings.ToLower(str)
str = strings.ReplaceAll(str, "/", "-")
str = strings.ReplaceAll(str, "_", "-")
if diff := len(str) + len(postfix) - 63; diff > 0 {
str = str[:len(str)-diff]
}
return str + postfix
}
func RunFunctionsInParallelAndCheckErrors(t *testing.T, functions []func() error) {
t.Helper()
var eg errgroup.Group
for _, function := range functions {
eg.Go(function)
}
require.NoError(t, eg.Wait())
}