Add English translation for "unique" validation.

pull/419/head
Sam Wang 6 years ago
parent 1fa3c8d633
commit df107f0184
  1. 5
      translations/en/en.go
  2. 18
      translations/en/en_test.go

@ -1293,6 +1293,11 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation: "{0} must contain a valid MAC address",
override: false,
},
{
tag: "unique",
translation: "{0} must contain unique values",
override: false,
},
{
tag: "iscolor",
translation: "{0} must be a valid color",

@ -138,6 +138,9 @@ func TestTranslations(t *testing.T) {
StrPtrGte *string `validate:"gte=10"`
OneOfString string `validate:"oneof=red green"`
OneOfInt int `validate:"oneof=5 63"`
UniqueSlice []string `validate:"unique"`
UniqueArray [3]string `validate:"unique"`
UniqueMap map[string]string `validate:"unique"`
}
var test Test
@ -184,6 +187,9 @@ func TestTranslations(t *testing.T) {
test.StrPtrMaxLen = &s
test.StrPtrLen = &s
test.UniqueSlice = []string{"1234", "1234"}
test.UniqueMap = map[string]string{"key1": "1234", "key2": "1234"}
err = validate.Struct(test)
NotEqual(t, err, nil)
@ -614,6 +620,18 @@ func TestTranslations(t *testing.T) {
ns: "Test.OneOfInt",
expected: "OneOfInt must be one of [5 63]",
},
{
ns: "Test.UniqueSlice",
expected: "UniqueSlice must contain unique values",
},
{
ns: "Test.UniqueArray",
expected: "UniqueArray must contain unique values",
},
{
ns: "Test.UniqueMap",
expected: "UniqueMap must contain unique values",
},
}
for _, tt := range tests {

Loading…
Cancel
Save