github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/pkg/names.go (about) 1 // Copyright (c) 2023, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package pkg 5 6 import ( 7 "k8s.io/apimachinery/pkg/util/rand" 8 "strings" 9 ) 10 11 type NameGenerator struct { 12 length int 13 charset []rune 14 } 15 16 var SimpleNameGenerator = newNameGenerator() 17 18 func newNameGenerator() NameGenerator { 19 var charset []rune 20 for i := 'a'; i <= 'z'; i++ { 21 charset = append(charset, i) 22 } 23 return NameGenerator{ 24 length: 5, 25 charset: charset, 26 } 27 } 28 29 func (n NameGenerator) New(prefix string) string { 30 sb := strings.Builder{} 31 sb.WriteString(prefix) 32 for i := 0; i < n.length; i++ { 33 sb.WriteRune(n.charset[rand.Intn(len(n.charset))]) 34 } 35 return sb.String() 36 }