Skip to content

Commit

Permalink
Merge pull request #1732 from actiontech/issue-1731
Browse files Browse the repository at this point in the history
change limitation of workflow name
  • Loading branch information
sjjian authored Aug 14, 2023
2 parents 2515c4d + 9edf942 commit 1096379
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion sqle/api/controller/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (cv *CustomValidator) RegisterTranslation(tag, enText, zhText string, param
return err
}

var ValidateNameRegexpPattern = "^[a-zA-Z\u4e00-\u9fa5][a-zA-Z0-9\u4e00-\u9fa5_-]{0,59}$"
var ValidateNameRegexpPattern = "^[a-zA-Z\u4e00-\u9fa5][a-zA-Z0-9\u4e00-\u9fa5_-]{0,119}$"

// ValidateName implements validator.Func
func ValidateName(fl validator.FieldLevel) bool {
Expand Down
18 changes: 9 additions & 9 deletions sqle/api/controller/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ func TestValidateName(t *testing.T) {
assert.Equal(t, true, validateName("姓名name_1"))
assert.Equal(t, true, validateName("name_1"))

len60 := `test_name_length_60_0000000000000000000000000000000000000000`
assert.Equal(t, 60, len(len60))
assert.Equal(t, true, validateName(len60))
len120 := `test_name_length_120_000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000`
assert.Equal(t, 120, len(len120))
assert.Equal(t, true, validateName(len120))

assert.Equal(t, false, validateName(""))
assert.Equal(t, false, validateName("1name姓名"))
Expand All @@ -28,10 +28,10 @@ func TestValidateName(t *testing.T) {
assert.Equal(t, false, validateName("name*name"))
assert.Equal(t, false, validateName("*name姓名"))

len61 := `test_name_length_61_00000000000000000000000000000000000000000`
assert.Equal(t, 61, len(len61))
assert.Equal(t, false, validateName(len61))
assert.Equal(t, false, validateName(len61+"*"))
len121 := `test_name_length_121_0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000`
assert.Equal(t, 121, len(len121))
assert.Equal(t, false, validateName(len121))
assert.Equal(t, false, validateName(len121+"*"))
}

func TestValidatePort(t *testing.T) {
Expand All @@ -50,14 +50,14 @@ func TestCustomValidateErrorMessage(t *testing.T) {
type tSingleError struct {
Name string `json:"name" valid:"name"`
}
assert.Equal(t, "tSingleError.name must match regexp `^[a-zA-Z一-龥][a-zA-Z0-9一-龥_-]{0,59}$`",
assert.Equal(t, "tSingleError.name must match regexp `^[a-zA-Z一-龥][a-zA-Z0-9一-龥_-]{0,119}$`",
Validate(&tSingleError{Name: "_name"}).Error())

type tMultiError struct {
Name string `json:"name" valid:"name"`
Port string `json:"port" valid:"port"`
}
assert.Equal(t, "tMultiError.name must match regexp `^[a-zA-Z一-龥][a-zA-Z0-9一-龥_-]{0,59}$`; "+
assert.Equal(t, "tMultiError.name must match regexp `^[a-zA-Z一-龥][a-zA-Z0-9一-龥_-]{0,119}$`; "+
"tMultiError.port is invalid port",
Validate(&tMultiError{Name: "_name", Port: "0"}).Error())
}

0 comments on commit 1096379

Please sign in to comment.