github.com/argoproj/argo-cd@v1.8.7/test/e2e/fixture/util.go (about)

     1  package fixture
     2  
     3  import (
     4  	"regexp"
     5  	"strings"
     6  )
     7  
     8  var (
     9  	matchFirstCap = regexp.MustCompile("(.)([A-Z][a-z]+)")
    10  	matchAllCap   = regexp.MustCompile("([a-z0-9])([A-Z])")
    11  )
    12  
    13  // returns dns friends string which is no longer than 63 characters and has specified postfix at the end
    14  func DnsFriendly(str string, postfix string) string {
    15  	str = matchFirstCap.ReplaceAllString(str, "${1}-${2}")
    16  	str = matchAllCap.ReplaceAllString(str, "${1}-${2}")
    17  	str = strings.ToLower(str)
    18  
    19  	if diff := len(str) + len(postfix) - 63; diff > 0 {
    20  		str = str[:len(str)-diff]
    21  	}
    22  	return str + postfix
    23  }