|
|
|
@ -7,7 +7,7 @@ import ( |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
. "github.com/go-playground/assert/v2" |
|
|
|
|
russian "github.com/go-playground/locales/en" |
|
|
|
|
russian "github.com/go-playground/locales/ru" |
|
|
|
|
ut "github.com/go-playground/universal-translator" |
|
|
|
|
"github.com/go-playground/validator/v10" |
|
|
|
|
) |
|
|
|
@ -40,12 +40,18 @@ func TestTranslations(t *testing.T) { |
|
|
|
|
LenString string `validate:"len=1"` |
|
|
|
|
LenNumber float64 `validate:"len=1113.00"` |
|
|
|
|
LenMultiple []string `validate:"len=7"` |
|
|
|
|
LenMultipleSecond []string `validate:"len=2"` |
|
|
|
|
MinString string `validate:"min=1"` |
|
|
|
|
MinStringMultiple string `validate:"min=2"` |
|
|
|
|
MinStringMultipleSecond string `validate:"min=7"` |
|
|
|
|
MinNumber float64 `validate:"min=1113.00"` |
|
|
|
|
MinMultiple []string `validate:"min=7"` |
|
|
|
|
MinMultipleSecond []string `validate:"min=2"` |
|
|
|
|
MaxString string `validate:"max=3"` |
|
|
|
|
MaxStringSecond string `validate:"max=7"` |
|
|
|
|
MaxNumber float64 `validate:"max=1113.00"` |
|
|
|
|
MaxMultiple []string `validate:"max=7"` |
|
|
|
|
MaxMultipleSecond []string `validate:"max=2"` |
|
|
|
|
EqString string `validate:"eq=3"` |
|
|
|
|
EqNumber float64 `validate:"eq=2.33"` |
|
|
|
|
EqMultiple []string `validate:"eq=7"` |
|
|
|
@ -53,20 +59,28 @@ func TestTranslations(t *testing.T) { |
|
|
|
|
NeNumber float64 `validate:"ne=0.00"` |
|
|
|
|
NeMultiple []string `validate:"ne=0"` |
|
|
|
|
LtString string `validate:"lt=3"` |
|
|
|
|
LtStringSecond string `validate:"lt=7"` |
|
|
|
|
LtNumber float64 `validate:"lt=5.56"` |
|
|
|
|
LtMultiple []string `validate:"lt=2"` |
|
|
|
|
LtMultipleSecond []string `validate:"lt=7"` |
|
|
|
|
LtTime time.Time `validate:"lt"` |
|
|
|
|
LteString string `validate:"lte=3"` |
|
|
|
|
LteStringSecond string `validate:"lte=7"` |
|
|
|
|
LteNumber float64 `validate:"lte=5.56"` |
|
|
|
|
LteMultiple []string `validate:"lte=2"` |
|
|
|
|
LteMultipleSecond []string `validate:"lte=7"` |
|
|
|
|
LteTime time.Time `validate:"lte"` |
|
|
|
|
GtString string `validate:"gt=3"` |
|
|
|
|
GtStringSecond string `validate:"gt=7"` |
|
|
|
|
GtNumber float64 `validate:"gt=5.56"` |
|
|
|
|
GtMultiple []string `validate:"gt=2"` |
|
|
|
|
GtMultipleSecond []string `validate:"gt=7"` |
|
|
|
|
GtTime time.Time `validate:"gt"` |
|
|
|
|
GteString string `validate:"gte=3"` |
|
|
|
|
GteStringSecond string `validate:"gte=7"` |
|
|
|
|
GteNumber float64 `validate:"gte=5.56"` |
|
|
|
|
GteMultiple []string `validate:"gte=2"` |
|
|
|
|
GteMultipleSecond []string `validate:"gte=7"` |
|
|
|
|
GteTime time.Time `validate:"gte"` |
|
|
|
|
EqFieldString string `validate:"eqfield=MaxString"` |
|
|
|
|
EqCSFieldString string `validate:"eqcsfield=Inner.EqCSFieldString"` |
|
|
|
@ -132,12 +146,18 @@ func TestTranslations(t *testing.T) { |
|
|
|
|
MAC string `validate:"mac"` |
|
|
|
|
IsColor string `validate:"iscolor"` |
|
|
|
|
StrPtrMinLen *string `validate:"min=10"` |
|
|
|
|
StrPtrMinLenSecond *string `validate:"min=2"` |
|
|
|
|
StrPtrMaxLen *string `validate:"max=1"` |
|
|
|
|
StrPtrLen *string `validate:"len=2"` |
|
|
|
|
StrPtrLenSecond *string `validate:"len=7"` |
|
|
|
|
StrPtrLt *string `validate:"lt=1"` |
|
|
|
|
StrPtrLte *string `validate:"lte=1"` |
|
|
|
|
StrPtrLteMultiple *string `validate:"lte=2"` |
|
|
|
|
StrPtrLteMultipleSecond *string `validate:"lte=7"` |
|
|
|
|
StrPtrGt *string `validate:"gt=10"` |
|
|
|
|
StrPtrGte *string `validate:"gte=10"` |
|
|
|
|
StrPtrGtSecond *string `validate:"gt=2"` |
|
|
|
|
StrPtrGteSecond *string `validate:"gte=2"` |
|
|
|
|
OneOfString string `validate:"oneof=red green"` |
|
|
|
|
OneOfInt int `validate:"oneof=5 63"` |
|
|
|
|
UniqueSlice []string `validate:"unique"` |
|
|
|
@ -152,17 +172,23 @@ func TestTranslations(t *testing.T) { |
|
|
|
|
test.Inner.GteCSFieldString = "1234" |
|
|
|
|
|
|
|
|
|
test.MaxString = "1234" |
|
|
|
|
test.MaxStringSecond = "12345678" |
|
|
|
|
test.MaxNumber = 2000 |
|
|
|
|
test.MaxMultiple = make([]string, 9) |
|
|
|
|
test.MaxMultipleSecond = make([]string, 3) |
|
|
|
|
|
|
|
|
|
test.LtString = "1234" |
|
|
|
|
test.LtStringSecond = "12345678" |
|
|
|
|
test.LtNumber = 6 |
|
|
|
|
test.LtMultiple = make([]string, 3) |
|
|
|
|
test.LtMultipleSecond = make([]string, 8) |
|
|
|
|
test.LtTime = time.Now().Add(time.Hour * 24) |
|
|
|
|
|
|
|
|
|
test.LteString = "1234" |
|
|
|
|
test.LteStringSecond = "12345678" |
|
|
|
|
test.LteNumber = 6 |
|
|
|
|
test.LteMultiple = make([]string, 3) |
|
|
|
|
test.LteMultipleSecond = make([]string, 8) |
|
|
|
|
test.LteTime = time.Now().Add(time.Hour * 24) |
|
|
|
|
|
|
|
|
|
test.LtFieldString = "12345" |
|
|
|
@ -452,15 +478,23 @@ func TestTranslations(t *testing.T) { |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.GteString", |
|
|
|
|
expected: "GteString должен содержать минимум 3 символы", |
|
|
|
|
expected: "GteString должен содержать минимум 3 символа", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.GteStringSecond", |
|
|
|
|
expected: "GteStringSecond должен содержать минимум 7 символов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.GteNumber", |
|
|
|
|
expected: "GteNumber должен быть больше или равно 5.56", |
|
|
|
|
expected: "GteNumber должен быть больше или равно 5,56", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.GteMultiple", |
|
|
|
|
expected: "GteMultiple должен содержать минимум 2 элементы", |
|
|
|
|
expected: "GteMultiple должен содержать минимум 2 элемента", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.GteMultipleSecond", |
|
|
|
|
expected: "GteMultipleSecond должен содержать минимум 7 элементов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.GteTime", |
|
|
|
@ -468,15 +502,23 @@ func TestTranslations(t *testing.T) { |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.GtString", |
|
|
|
|
expected: "GtString должен быть длиннее 3 символы", |
|
|
|
|
expected: "GtString должен быть длиннее 3 символов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.GtStringSecond", |
|
|
|
|
expected: "GtStringSecond должен быть длиннее 7 символов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.GtNumber", |
|
|
|
|
expected: "GtNumber должен быть больше 5.56", |
|
|
|
|
expected: "GtNumber должен быть больше 5,56", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.GtMultiple", |
|
|
|
|
expected: "GtMultiple должен содержать более 2 элементы", |
|
|
|
|
expected: "GtMultiple должен содержать более 2 элементов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.GtMultipleSecond", |
|
|
|
|
expected: "GtMultipleSecond должен содержать более 7 элементов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.GtTime", |
|
|
|
@ -484,15 +526,23 @@ func TestTranslations(t *testing.T) { |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.LteString", |
|
|
|
|
expected: "LteString должен содержать максимум 3 символы", |
|
|
|
|
expected: "LteString должен содержать максимум 3 символа", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.LteStringSecond", |
|
|
|
|
expected: "LteStringSecond должен содержать максимум 7 символов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.LteNumber", |
|
|
|
|
expected: "LteNumber должен быть менее или равен 5.56", |
|
|
|
|
expected: "LteNumber должен быть менее или равен 5,56", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.LteMultiple", |
|
|
|
|
expected: "LteMultiple должен содержать максимум 2 элементы", |
|
|
|
|
expected: "LteMultiple должен содержать максимум 2 элемента", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.LteMultipleSecond", |
|
|
|
|
expected: "LteMultipleSecond должен содержать максимум 7 элементов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.LteTime", |
|
|
|
@ -500,15 +550,23 @@ func TestTranslations(t *testing.T) { |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.LtString", |
|
|
|
|
expected: "LtString должен иметь менее 3 символы", |
|
|
|
|
expected: "LtString должен иметь менее 3 символов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.LtStringSecond", |
|
|
|
|
expected: "LtStringSecond должен иметь менее 7 символов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.LtNumber", |
|
|
|
|
expected: "LtNumber должен быть менее 5.56", |
|
|
|
|
expected: "LtNumber должен быть менее 5,56", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.LtMultiple", |
|
|
|
|
expected: "LtMultiple должен содержать менее 2 элементы", |
|
|
|
|
expected: "LtMultiple должен содержать менее 2 элементов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.LtMultipleSecond", |
|
|
|
|
expected: "LtMultipleSecond должен содержать менее 7 элементов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.LtTime", |
|
|
|
@ -540,27 +598,47 @@ func TestTranslations(t *testing.T) { |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.MaxString", |
|
|
|
|
expected: "MaxString должен содержать максимум 3 символы", |
|
|
|
|
expected: "MaxString должен содержать максимум 3 символа", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.MaxStringSecond", |
|
|
|
|
expected: "MaxStringSecond должен содержать максимум 7 символов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.MaxNumber", |
|
|
|
|
expected: "MaxNumber должен быть меньше или равно 1,113.00", |
|
|
|
|
expected: "MaxNumber должен быть меньше или равно 1 113,00", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.MaxMultiple", |
|
|
|
|
expected: "MaxMultiple должен содержать максимум 7 элементы", |
|
|
|
|
expected: "MaxMultiple должен содержать максимум 7 элементов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.MaxMultipleSecond", |
|
|
|
|
expected: "MaxMultipleSecond должен содержать максимум 2 элемента", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.MinString", |
|
|
|
|
expected: "MinString должен содержать минимум 1 символ", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.MinStringMultiple", |
|
|
|
|
expected: "MinStringMultiple должен содержать минимум 2 символа", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.MinStringMultipleSecond", |
|
|
|
|
expected: "MinStringMultipleSecond должен содержать минимум 7 символов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.MinNumber", |
|
|
|
|
expected: "MinNumber должен быть больше или равно 1,113.00", |
|
|
|
|
expected: "MinNumber должен быть больше или равно 1 113,00", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.MinMultiple", |
|
|
|
|
expected: "MinMultiple должен содержать минимум 7 элементы", |
|
|
|
|
expected: "MinMultiple должен содержать минимум 7 элементов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.MinMultipleSecond", |
|
|
|
|
expected: "MinMultipleSecond должен содержать минимум 2 элемента", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.LenString", |
|
|
|
@ -568,11 +646,15 @@ func TestTranslations(t *testing.T) { |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.LenNumber", |
|
|
|
|
expected: "LenNumber должен быть равен 1,113.00", |
|
|
|
|
expected: "LenNumber должен быть равен 1 113,00", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.LenMultiple", |
|
|
|
|
expected: "LenMultiple должен содержать 7 элементы", |
|
|
|
|
expected: "LenMultiple должен содержать 7 элементов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.LenMultipleSecond", |
|
|
|
|
expected: "LenMultipleSecond должен содержать 2 элемента", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.RequiredString", |
|
|
|
@ -588,7 +670,11 @@ func TestTranslations(t *testing.T) { |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.StrPtrMinLen", |
|
|
|
|
expected: "StrPtrMinLen должен содержать минимум 10 символы", |
|
|
|
|
expected: "StrPtrMinLen должен содержать минимум 10 символов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.StrPtrMinLenSecond", |
|
|
|
|
expected: "StrPtrMinLenSecond должен содержать минимум 2 символа", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.StrPtrMaxLen", |
|
|
|
@ -596,7 +682,11 @@ func TestTranslations(t *testing.T) { |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.StrPtrLen", |
|
|
|
|
expected: "StrPtrLen должен быть длиной в 2 символы", |
|
|
|
|
expected: "StrPtrLen должен быть длиной в 2 символа", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.StrPtrLenSecond", |
|
|
|
|
expected: "StrPtrLenSecond должен быть длиной в 7 символов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.StrPtrLt", |
|
|
|
@ -606,13 +696,29 @@ func TestTranslations(t *testing.T) { |
|
|
|
|
ns: "Test.StrPtrLte", |
|
|
|
|
expected: "StrPtrLte должен содержать максимум 1 символ", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.StrPtrLteMultiple", |
|
|
|
|
expected: "StrPtrLteMultiple должен содержать максимум 2 символа", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.StrPtrLteMultipleSecond", |
|
|
|
|
expected: "StrPtrLteMultipleSecond должен содержать максимум 7 символов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.StrPtrGt", |
|
|
|
|
expected: "StrPtrGt должен быть длиннее 10 символы", |
|
|
|
|
expected: "StrPtrGt должен быть длиннее 10 символов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.StrPtrGtSecond", |
|
|
|
|
expected: "StrPtrGtSecond должен быть длиннее 2 символов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.StrPtrGte", |
|
|
|
|
expected: "StrPtrGte должен содержать минимум 10 символы", |
|
|
|
|
expected: "StrPtrGte должен содержать минимум 10 символов", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.StrPtrGteSecond", |
|
|
|
|
expected: "StrPtrGteSecond должен содержать минимум 2 символа", |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
ns: "Test.OneOfString", |
|
|
|
|