From 6adbfa2dbc2765c3910e4ee81c3907be4ef8a854 Mon Sep 17 00:00:00 2001 From: luowei Date: Mon, 14 Aug 2023 11:17:29 +0800 Subject: [PATCH 1/2] change limitation of workflow name --- sqle/api/controller/validator.go | 2 +- sqle/api/controller/validator_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sqle/api/controller/validator.go b/sqle/api/controller/validator.go index bc643ace32..0bdff11c88 100644 --- a/sqle/api/controller/validator.go +++ b/sqle/api/controller/validator.go @@ -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 { diff --git a/sqle/api/controller/validator_test.go b/sqle/api/controller/validator_test.go index be9b50b0f8..a4da31bcd9 100644 --- a/sqle/api/controller/validator_test.go +++ b/sqle/api/controller/validator_test.go @@ -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()) } From 9edf942c55586ff546f8bd69d1da219d5b6248b4 Mon Sep 17 00:00:00 2001 From: luowei Date: Mon, 14 Aug 2023 13:17:28 +0800 Subject: [PATCH 2/2] fix unit test --- sqle/api/controller/validator_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sqle/api/controller/validator_test.go b/sqle/api/controller/validator_test.go index a4da31bcd9..3f622ab490 100644 --- a/sqle/api/controller/validator_test.go +++ b/sqle/api/controller/validator_test.go @@ -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姓名")) @@ -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) {