chore: fix tests

This commit is contained in:
Steven
2024-08-20 23:52:49 +08:00
parent 340025002b
commit a44e3e23d9
5 changed files with 276 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"math/big"
"net/mail"
"net/url"
"strconv"
"strings"
"unicode/utf8"
@ -146,11 +147,17 @@ func TruncateString(str string, limit int) (string, bool) {
return str, false
}
// TruncateStringWithDescription tries to truncate the string and append "... (view details in Bytebase)" if truncated.
// TruncateStringWithDescription tries to truncate the string and append "..." if truncated.
func TruncateStringWithDescription(str string) string {
const limit = 450
if truncatedStr, truncated := TruncateString(str, limit); truncated {
return fmt.Sprintf("%s... (view details in Bytebase)", truncatedStr)
return fmt.Sprintf("%s...", truncatedStr)
}
return str
}
// ValidateURI validates the URI.
func ValidateURI(uri string) bool {
u, err := url.Parse(uri)
return err == nil && u.Scheme != "" && u.Host != ""
}