add more test cases and fix typo
Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
This commit is contained in:
parent
860df2294b
commit
eac230f93e
@ -82,7 +82,7 @@ func ComputeSecureUniqueDeterministicNameFromData(fullName string, maxNameLength
|
||||
return fmt.Sprintf("%s-%08x", prefix, hashResult), nil
|
||||
}
|
||||
|
||||
// DNSSafeShortenToNCharacters shortens the input string to 52 chars and ensures the last char is an alpha-numeric character.
|
||||
// DNSSafeShortenToNCharacters shortens the input string to N chars and ensures the last char is an alpha-numeric character.
|
||||
func DNSSafeShortenToNCharacters(in string, maxLength int) string {
|
||||
var alphaNumeric = regexp.MustCompile(`[a-zA-Z\d]`)
|
||||
|
||||
|
||||
@ -122,6 +122,26 @@ func TestDNSSafeShortenToNCharacters(t *testing.T) {
|
||||
}
|
||||
|
||||
tests := []testcase{
|
||||
{
|
||||
in: "aaaaaaaaaaaaaaa",
|
||||
maxLength: 0,
|
||||
expOut: "",
|
||||
},
|
||||
{
|
||||
in: "aa-----aaaa",
|
||||
maxLength: 5,
|
||||
expOut: "aa",
|
||||
},
|
||||
{
|
||||
in: "aa11111aaaa",
|
||||
maxLength: 5,
|
||||
expOut: "aa111",
|
||||
},
|
||||
{
|
||||
in: "aaAAAAAaaaa",
|
||||
maxLength: 5,
|
||||
expOut: "aaAAA",
|
||||
},
|
||||
{
|
||||
in: "aaaaaaaaaaaaaaa",
|
||||
maxLength: 3,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user