1 package lv
2
3 import (
4 "testing"
5 "time"
6
7 . "github.com/go-playground/assert/v2"
8 english "github.com/go-playground/locales/en"
9 ut "github.com/go-playground/universal-translator"
10 "github.com/go-playground/validator/v10"
11 )
12
13 func TestTranslations(t *testing.T) {
14 eng := english.New()
15 uni := ut.New(eng, eng)
16 trans, _ := uni.GetTranslator("en")
17
18 validate := validator.New()
19
20 err := RegisterDefaultTranslations(validate, trans)
21 Equal(t, err, nil)
22
23 type Inner struct {
24 EqCSFieldString string
25 NeCSFieldString string
26 GtCSFieldString string
27 GteCSFieldString string
28 LtCSFieldString string
29 LteCSFieldString string
30 RequiredIf string
31 }
32
33 type Test struct {
34 Inner Inner
35 RequiredString string `validate:"required"`
36 RequiredNumber int `validate:"required"`
37 RequiredMultiple []string `validate:"required"`
38 RequiredIf string `validate:"required_if=Inner.RequiredIf abcd"`
39 LenString string `validate:"len=1"`
40 LenNumber float64 `validate:"len=1113.00"`
41 LenMultiple []string `validate:"len=7"`
42 MinString string `validate:"min=1"`
43 MinNumber float64 `validate:"min=1113.00"`
44 MinMultiple []string `validate:"min=7"`
45 MaxString string `validate:"max=3"`
46 MaxNumber float64 `validate:"max=1113.00"`
47 MaxMultiple []string `validate:"max=7"`
48 EqString string `validate:"eq=3"`
49 EqNumber float64 `validate:"eq=2.33"`
50 EqMultiple []string `validate:"eq=7"`
51 NeString string `validate:"ne="`
52 NeNumber float64 `validate:"ne=0.00"`
53 NeMultiple []string `validate:"ne=0"`
54 LtString string `validate:"lt=3"`
55 LtNumber float64 `validate:"lt=5.56"`
56 LtMultiple []string `validate:"lt=2"`
57 LtTime time.Time `validate:"lt"`
58 LteString string `validate:"lte=3"`
59 LteNumber float64 `validate:"lte=5.56"`
60 LteMultiple []string `validate:"lte=2"`
61 LteTime time.Time `validate:"lte"`
62 GtString string `validate:"gt=3"`
63 GtNumber float64 `validate:"gt=5.56"`
64 GtMultiple []string `validate:"gt=2"`
65 GtTime time.Time `validate:"gt"`
66 GteString string `validate:"gte=3"`
67 GteNumber float64 `validate:"gte=5.56"`
68 GteMultiple []string `validate:"gte=2"`
69 GteTime time.Time `validate:"gte"`
70 EqFieldString string `validate:"eqfield=MaxString"`
71 EqCSFieldString string `validate:"eqcsfield=Inner.EqCSFieldString"`
72 NeCSFieldString string `validate:"necsfield=Inner.NeCSFieldString"`
73 GtCSFieldString string `validate:"gtcsfield=Inner.GtCSFieldString"`
74 GteCSFieldString string `validate:"gtecsfield=Inner.GteCSFieldString"`
75 LtCSFieldString string `validate:"ltcsfield=Inner.LtCSFieldString"`
76 LteCSFieldString string `validate:"ltecsfield=Inner.LteCSFieldString"`
77 NeFieldString string `validate:"nefield=EqFieldString"`
78 GtFieldString string `validate:"gtfield=MaxString"`
79 GteFieldString string `validate:"gtefield=MaxString"`
80 LtFieldString string `validate:"ltfield=MaxString"`
81 LteFieldString string `validate:"ltefield=MaxString"`
82 AlphaString string `validate:"alpha"`
83 AlphanumString string `validate:"alphanum"`
84 NumericString string `validate:"numeric"`
85 NumberString string `validate:"number"`
86 HexadecimalString string `validate:"hexadecimal"`
87 HexColorString string `validate:"hexcolor"`
88 RGBColorString string `validate:"rgb"`
89 RGBAColorString string `validate:"rgba"`
90 HSLColorString string `validate:"hsl"`
91 HSLAColorString string `validate:"hsla"`
92 Email string `validate:"email"`
93 URL string `validate:"url"`
94 URI string `validate:"uri"`
95 Base64 string `validate:"base64"`
96 Contains string `validate:"contains=purpose"`
97 ContainsAny string `validate:"containsany=!@#$"`
98 Excludes string `validate:"excludes=text"`
99 ExcludesAll string `validate:"excludesall=!@#$"`
100 ExcludesRune string `validate:"excludesrune=☻"`
101 ISBN string `validate:"isbn"`
102 ISBN10 string `validate:"isbn10"`
103 ISBN13 string `validate:"isbn13"`
104 ISSN string `validate:"issn"`
105 UUID string `validate:"uuid"`
106 UUID3 string `validate:"uuid3"`
107 UUID4 string `validate:"uuid4"`
108 UUID5 string `validate:"uuid5"`
109 ULID string `validate:"ulid"`
110 ASCII string `validate:"ascii"`
111 PrintableASCII string `validate:"printascii"`
112 MultiByte string `validate:"multibyte"`
113 DataURI string `validate:"datauri"`
114 Latitude string `validate:"latitude"`
115 Longitude string `validate:"longitude"`
116 SSN string `validate:"ssn"`
117 IP string `validate:"ip"`
118 IPv4 string `validate:"ipv4"`
119 IPv6 string `validate:"ipv6"`
120 CIDR string `validate:"cidr"`
121 CIDRv4 string `validate:"cidrv4"`
122 CIDRv6 string `validate:"cidrv6"`
123 TCPAddr string `validate:"tcp_addr"`
124 TCPAddrv4 string `validate:"tcp4_addr"`
125 TCPAddrv6 string `validate:"tcp6_addr"`
126 UDPAddr string `validate:"udp_addr"`
127 UDPAddrv4 string `validate:"udp4_addr"`
128 UDPAddrv6 string `validate:"udp6_addr"`
129 IPAddr string `validate:"ip_addr"`
130 IPAddrv4 string `validate:"ip4_addr"`
131 IPAddrv6 string `validate:"ip6_addr"`
132 UinxAddr string `validate:"unix_addr"`
133 MAC string `validate:"mac"`
134 IsColor string `validate:"iscolor"`
135 StrPtrMinLen *string `validate:"min=10"`
136 StrPtrMaxLen *string `validate:"max=1"`
137 StrPtrLen *string `validate:"len=2"`
138 StrPtrLt *string `validate:"lt=1"`
139 StrPtrLte *string `validate:"lte=1"`
140 StrPtrGt *string `validate:"gt=10"`
141 StrPtrGte *string `validate:"gte=10"`
142 OneOfString string `validate:"oneof=red green"`
143 OneOfInt int `validate:"oneof=5 63"`
144 UniqueSlice []string `validate:"unique"`
145 UniqueArray [3]string `validate:"unique"`
146 UniqueMap map[string]string `validate:"unique"`
147 JSONString string `validate:"json"`
148 JWTString string `validate:"jwt"`
149 LowercaseString string `validate:"lowercase"`
150 UppercaseString string `validate:"uppercase"`
151 Datetime string `validate:"datetime=2006-01-02"`
152 PostCode string `validate:"postcode_iso3166_alpha2=SG"`
153 PostCodeCountry string
154 PostCodeByField string `validate:"postcode_iso3166_alpha2_field=PostCodeCountry"`
155 BooleanString string `validate:"boolean"`
156 }
157
158 var test Test
159
160 test.Inner.EqCSFieldString = "1234"
161 test.Inner.GtCSFieldString = "1234"
162 test.Inner.GteCSFieldString = "1234"
163
164 test.MaxString = "1234"
165 test.MaxNumber = 2000
166 test.MaxMultiple = make([]string, 9)
167
168 test.LtString = "1234"
169 test.LtNumber = 6
170 test.LtMultiple = make([]string, 3)
171 test.LtTime = time.Now().Add(time.Hour * 24)
172
173 test.LteString = "1234"
174 test.LteNumber = 6
175 test.LteMultiple = make([]string, 3)
176 test.LteTime = time.Now().Add(time.Hour * 24)
177
178 test.LtFieldString = "12345"
179 test.LteFieldString = "12345"
180
181 test.LtCSFieldString = "1234"
182 test.LteCSFieldString = "1234"
183
184 test.AlphaString = "abc3"
185 test.AlphanumString = "abc3!"
186 test.NumericString = "12E.00"
187 test.NumberString = "12E"
188
189 test.Excludes = "this is some test text"
190 test.ExcludesAll = "This is Great!"
191 test.ExcludesRune = "Love it ☻"
192
193 test.ASCII = "カタカナ"
194 test.PrintableASCII = "カタカナ"
195
196 test.MultiByte = "1234feerf"
197
198 test.LowercaseString = "ABCDEFG"
199 test.UppercaseString = "abcdefg"
200
201 s := "toolong"
202 test.StrPtrMaxLen = &s
203 test.StrPtrLen = &s
204
205 test.UniqueSlice = []string{"1234", "1234"}
206 test.UniqueMap = map[string]string{"key1": "1234", "key2": "1234"}
207 test.Datetime = "2008-Feb-01"
208 test.BooleanString = "A"
209
210 test.Inner.RequiredIf = "abcd"
211
212 err = validate.Struct(test)
213 NotEqual(t, err, nil)
214
215 errs, ok := err.(validator.ValidationErrors)
216 Equal(t, ok, true)
217
218 tests := []struct {
219 ns string
220 expected string
221 }{
222 {
223 ns: "Test.IsColor",
224 expected: "IsColor jābūt derīgai krāsai",
225 },
226 {
227 ns: "Test.MAC",
228 expected: "MAC jābūt derīgai MAC adresei",
229 },
230 {
231 ns: "Test.IPAddr",
232 expected: "IPAddr jābūt atrisināmai IP adresei",
233 },
234 {
235 ns: "Test.IPAddrv4",
236 expected: "IPAddrv4 jābūt atrisināmai IPv4 adresei",
237 },
238 {
239 ns: "Test.IPAddrv6",
240 expected: "IPAddrv6 jābūt atrisināmai IPv6 adresei",
241 },
242 {
243 ns: "Test.UDPAddr",
244 expected: "UDPAddr jābūt derīgai UDP adresei",
245 },
246 {
247 ns: "Test.UDPAddrv4",
248 expected: "UDPAddrv4 jābūt derīgai IPv4 UDP adresei",
249 },
250 {
251 ns: "Test.UDPAddrv6",
252 expected: "UDPAddrv6 jābūt derīgai IPv6 UDP adresei",
253 },
254 {
255 ns: "Test.TCPAddr",
256 expected: "TCPAddr jābūt derīgai TCP adresei",
257 },
258 {
259 ns: "Test.TCPAddrv4",
260 expected: "TCPAddrv4 jābūt derīgai IPv4 TCP adresei",
261 },
262 {
263 ns: "Test.TCPAddrv6",
264 expected: "TCPAddrv6 jābūt derīgai IPv6 TCP adresei",
265 },
266 {
267 ns: "Test.CIDR",
268 expected: "CIDR jāsatur derīgu CIDR notāciju",
269 },
270 {
271 ns: "Test.CIDRv4",
272 expected: "CIDRv4 jāsatur derīgu CIDR notāciju IPv4 adresei",
273 },
274 {
275 ns: "Test.CIDRv6",
276 expected: "CIDRv6 jāsatur derīgu CIDR notāciju IPv6 adresei",
277 },
278 {
279 ns: "Test.SSN",
280 expected: "SSN jābūt derīgam SSN numuram",
281 },
282 {
283 ns: "Test.IP",
284 expected: "IP jābūt derīgai IP adresei",
285 },
286 {
287 ns: "Test.IPv4",
288 expected: "IPv4 jābūt derīgai IPv4 adresei",
289 },
290 {
291 ns: "Test.IPv6",
292 expected: "IPv6 jābūt derīgai IPv6 adresei",
293 },
294 {
295 ns: "Test.DataURI",
296 expected: "DataURI jāsatur derīgs Data URI",
297 },
298 {
299 ns: "Test.Latitude",
300 expected: "Latitude jāsatur derīgus platuma grādus",
301 },
302 {
303 ns: "Test.Longitude",
304 expected: "Longitude jāsatur derīgus garuma grādus",
305 },
306 {
307 ns: "Test.MultiByte",
308 expected: "MultiByte jāsatur multibyte rakstu zīmes",
309 },
310 {
311 ns: "Test.ASCII",
312 expected: "ASCII jāsatur tikai ascii rakstu zīmes",
313 },
314 {
315 ns: "Test.PrintableASCII",
316 expected: "PrintableASCII jāsatur tikai drukājamas ascii rakstu zīmes",
317 },
318 {
319 ns: "Test.UUID",
320 expected: "UUID jābūt derīgam UUID",
321 },
322 {
323 ns: "Test.UUID3",
324 expected: "UUID3 jābūt derīgam 3. versijas UUID",
325 },
326 {
327 ns: "Test.UUID4",
328 expected: "UUID4 jābūt derīgam 4. versijas UUID",
329 },
330 {
331 ns: "Test.UUID5",
332 expected: "UUID5 jābūt derīgam 5. versijas UUID",
333 },
334 {
335 ns: "Test.ULID",
336 expected: "ULID jābūt derīgam ULID",
337 },
338 {
339 ns: "Test.ISBN",
340 expected: "ISBN jābūt derīgam ISBN numuram",
341 },
342 {
343 ns: "Test.ISBN10",
344 expected: "ISBN10 jābūt derīgam ISBN-10 numuram",
345 },
346 {
347 ns: "Test.ISBN13",
348 expected: "ISBN13 jābūt derīgam ISBN-13 numuram",
349 },
350 {
351 ns: "Test.ISSN",
352 expected: "ISSN jābūt derīgam ISSN numuram",
353 },
354 {
355 ns: "Test.Excludes",
356 expected: "Excludes nedrīkst saturēt tekstu 'text'",
357 },
358 {
359 ns: "Test.ExcludesAll",
360 expected: "ExcludesAll nedrīkst saturēt nevienu no sekojošām rakstu zīmēm '!@#$'",
361 },
362 {
363 ns: "Test.ExcludesRune",
364 expected: "ExcludesRune nedrīkst saturēt sekojošo '☻'",
365 },
366 {
367 ns: "Test.ContainsAny",
368 expected: "ContainsAny jāsatur minimums 1 no rakstu zīmēm '!@#$'",
369 },
370 {
371 ns: "Test.Contains",
372 expected: "Contains jāsatur teksts 'purpose'",
373 },
374 {
375 ns: "Test.Base64",
376 expected: "Base64 jābūt derīgai Base64 virknei",
377 },
378 {
379 ns: "Test.Email",
380 expected: "Email jābūt derīgai e-pasta adresei",
381 },
382 {
383 ns: "Test.URL",
384 expected: "URL jābūt derīgam URL",
385 },
386 {
387 ns: "Test.URI",
388 expected: "URI jābūt derīgam URI",
389 },
390 {
391 ns: "Test.RGBColorString",
392 expected: "RGBColorString jābūt derīgai RGB krāsai",
393 },
394 {
395 ns: "Test.RGBAColorString",
396 expected: "RGBAColorString jābūt derīgai RGBA krāsai",
397 },
398 {
399 ns: "Test.HSLColorString",
400 expected: "HSLColorString jābūt derīgai HSL krāsai",
401 },
402 {
403 ns: "Test.HSLAColorString",
404 expected: "HSLAColorString jābūt derīgai HSLA krāsai",
405 },
406 {
407 ns: "Test.HexadecimalString",
408 expected: "HexadecimalString jābūt heksadecimālam skaitlim",
409 },
410 {
411 ns: "Test.HexColorString",
412 expected: "HexColorString jābūt derīgai HEX krāsai",
413 },
414 {
415 ns: "Test.NumberString",
416 expected: "NumberString jāsatur derīgs skaitlis",
417 },
418 {
419 ns: "Test.NumericString",
420 expected: "NumericString jāsatur tikai cipari",
421 },
422 {
423 ns: "Test.AlphanumString",
424 expected: "AlphanumString jāsatur tikai simboli no alfabēta vai cipari (Alphanumeric)",
425 },
426 {
427 ns: "Test.AlphaString",
428 expected: "AlphaString jāsatur tikai simboli no alfabēta",
429 },
430 {
431 ns: "Test.LtFieldString",
432 expected: "LtFieldString jābūt mazākam par MaxString",
433 },
434 {
435 ns: "Test.LteFieldString",
436 expected: "LteFieldString jābūt mazākam par MaxString vai vienādam",
437 },
438 {
439 ns: "Test.GtFieldString",
440 expected: "GtFieldString jābūt lielākam par MaxString",
441 },
442 {
443 ns: "Test.GteFieldString",
444 expected: "GteFieldString jābūt lielākam par MaxString vai vienādam",
445 },
446 {
447 ns: "Test.NeFieldString",
448 expected: "NeFieldString nedrīkst būt vienāds ar EqFieldString",
449 },
450 {
451 ns: "Test.LtCSFieldString",
452 expected: "LtCSFieldString jābūt mazākam par Inner.LtCSFieldString",
453 },
454 {
455 ns: "Test.LteCSFieldString",
456 expected: "LteCSFieldString jābūt mazākam par Inner.LteCSFieldString vai vienādam",
457 },
458 {
459 ns: "Test.GtCSFieldString",
460 expected: "GtCSFieldString jābūt lielākam par Inner.GtCSFieldString",
461 },
462 {
463 ns: "Test.GteCSFieldString",
464 expected: "GteCSFieldString jābūt lielākam par Inner.GteCSFieldString vai vienādam",
465 },
466 {
467 ns: "Test.NeCSFieldString",
468 expected: "NeCSFieldString nedrīkst būt vienāds ar Inner.NeCSFieldString",
469 },
470 {
471 ns: "Test.EqCSFieldString",
472 expected: "EqCSFieldString jābūt vienādam ar Inner.EqCSFieldString",
473 },
474 {
475 ns: "Test.EqFieldString",
476 expected: "EqFieldString jābūt vienādam ar MaxString",
477 },
478 {
479 ns: "Test.GteString",
480 expected: "GteString garumam jābūt minimums 3 rakstu zīmes",
481 },
482 {
483 ns: "Test.GteNumber",
484 expected: "GteNumber jābūt 5.56 vai lielākam",
485 },
486 {
487 ns: "Test.GteMultiple",
488 expected: "GteMultiple jāsatur minimums 2 elementi",
489 },
490 {
491 ns: "Test.GteTime",
492 expected: "GteTime jābūt lielākam par šī brīža Datumu un laiku vai vienādam",
493 },
494 {
495 ns: "Test.GtString",
496 expected: "GtString ir jābūt garākam par 3 rakstu zīmēm",
497 },
498 {
499 ns: "Test.GtNumber",
500 expected: "GtNumber jābūt lielākam par 5.56",
501 },
502 {
503 ns: "Test.GtMultiple",
504 expected: "GtMultiple jāsatur vairāk par 2 elementiem",
505 },
506 {
507 ns: "Test.GtTime",
508 expected: "GtTime jābūt lielākam par šī brīža Datumu un laiku",
509 },
510 {
511 ns: "Test.LteString",
512 expected: "LteString garumam jābūt maksimums 3 rakstu zīmes",
513 },
514 {
515 ns: "Test.LteNumber",
516 expected: "LteNumber jābūt 5.56 vai mazākam",
517 },
518 {
519 ns: "Test.LteMultiple",
520 expected: "LteMultiple jāsatur maksimums 2 elementi",
521 },
522 {
523 ns: "Test.LteTime",
524 expected: "LteTime jābūt mazākam par šī brīža Datumu un laiku vai vienādam",
525 },
526 {
527 ns: "Test.LtString",
528 expected: "LtString garumam jābūt mazākam par 3 rakstu zīmēm",
529 },
530 {
531 ns: "Test.LtNumber",
532 expected: "LtNumber jābūt mazākam par 5.56",
533 },
534 {
535 ns: "Test.LtMultiple",
536 expected: "LtMultiple jāsatur mazāk par 2 elementiem",
537 },
538 {
539 ns: "Test.LtTime",
540 expected: "LtTime jābūt mazākam par šī brīža Datumu un laiku",
541 },
542 {
543 ns: "Test.NeString",
544 expected: "NeString nedrīkst būt vienāds ar ",
545 },
546 {
547 ns: "Test.NeNumber",
548 expected: "NeNumber nedrīkst būt vienāds ar 0.00",
549 },
550 {
551 ns: "Test.NeMultiple",
552 expected: "NeMultiple nedrīkst būt vienāds ar 0",
553 },
554 {
555 ns: "Test.EqString",
556 expected: "EqString nav vienāds ar 3",
557 },
558 {
559 ns: "Test.EqNumber",
560 expected: "EqNumber nav vienāds ar 2.33",
561 },
562 {
563 ns: "Test.EqMultiple",
564 expected: "EqMultiple nav vienāds ar 7",
565 },
566 {
567 ns: "Test.MaxString",
568 expected: "MaxString vērtība pārsniedz maksimālo garumu 3 rakstu zīmes",
569 },
570 {
571 ns: "Test.MaxNumber",
572 expected: "MaxNumber vērtībai jābūt 1,113.00 vai mazākai",
573 },
574 {
575 ns: "Test.MaxMultiple",
576 expected: "MaxMultiple jāsatur maksimums 7 elementi",
577 },
578 {
579 ns: "Test.MinString",
580 expected: "MinString garumam jābūt minimums 1 rakstu zīme",
581 },
582 {
583 ns: "Test.MinNumber",
584 expected: "MinNumber vērtībai jābūt 1,113.00 vai lielākai",
585 },
586 {
587 ns: "Test.MinMultiple",
588 expected: "MinMultiple jāsatur minimums 7 elementi",
589 },
590 {
591 ns: "Test.LenString",
592 expected: "LenString garumam jābūt 1 rakstu zīme",
593 },
594 {
595 ns: "Test.LenNumber",
596 expected: "LenNumber vērtībai jābūt 1,113.00",
597 },
598 {
599 ns: "Test.LenMultiple",
600 expected: "LenMultiple vērtībai jāsatur 7 elementi",
601 },
602 {
603 ns: "Test.RequiredString",
604 expected: "RequiredString ir obligāts lauks",
605 },
606 {
607 ns: "Test.RequiredIf",
608 expected: "RequiredIf ir obligāts lauks",
609 },
610 {
611 ns: "Test.RequiredNumber",
612 expected: "RequiredNumber ir obligāts lauks",
613 },
614 {
615 ns: "Test.RequiredMultiple",
616 expected: "RequiredMultiple ir obligāts lauks",
617 },
618 {
619 ns: "Test.StrPtrMinLen",
620 expected: "StrPtrMinLen garumam jābūt minimums 10 rakstu zīmes",
621 },
622 {
623 ns: "Test.StrPtrMaxLen",
624 expected: "StrPtrMaxLen vērtība pārsniedz maksimālo garumu 1 rakstu zīme",
625 },
626 {
627 ns: "Test.StrPtrLen",
628 expected: "StrPtrLen garumam jābūt 2 rakstu zīmes",
629 },
630 {
631 ns: "Test.StrPtrLt",
632 expected: "StrPtrLt garumam jābūt mazākam par 1 rakstu zīmi",
633 },
634 {
635 ns: "Test.StrPtrLte",
636 expected: "StrPtrLte garumam jābūt maksimums 1 rakstu zīme",
637 },
638 {
639 ns: "Test.StrPtrGt",
640 expected: "StrPtrGt ir jābūt garākam par 10 rakstu zīmēm",
641 },
642 {
643 ns: "Test.StrPtrGte",
644 expected: "StrPtrGte garumam jābūt minimums 10 rakstu zīmes",
645 },
646 {
647 ns: "Test.OneOfString",
648 expected: "OneOfString jābūt vienam no [red green]",
649 },
650 {
651 ns: "Test.OneOfInt",
652 expected: "OneOfInt jābūt vienam no [5 63]",
653 },
654 {
655 ns: "Test.UniqueSlice",
656 expected: "UniqueSlice jāsatur unikālas vērtības",
657 },
658 {
659 ns: "Test.UniqueArray",
660 expected: "UniqueArray jāsatur unikālas vērtības",
661 },
662 {
663 ns: "Test.UniqueMap",
664 expected: "UniqueMap jāsatur unikālas vērtības",
665 },
666 {
667 ns: "Test.JSONString",
668 expected: "JSONString jābūt derīgai json virknei",
669 },
670 {
671 ns: "Test.JWTString",
672 expected: "JWTString jābūt derīgai jwt virknei",
673 },
674 {
675 ns: "Test.LowercaseString",
676 expected: "LowercaseString jābūt mazo burtu virknei",
677 },
678 {
679 ns: "Test.UppercaseString",
680 expected: "UppercaseString jābūt lielo burtu virknei",
681 },
682 {
683 ns: "Test.Datetime",
684 expected: "Datetime neatbilst formātam 2006-01-02",
685 },
686 {
687 ns: "Test.PostCode",
688 expected: "PostCode neatbilst pasta indeksa formātam valstī SG",
689 },
690 {
691 ns: "Test.PostCodeByField",
692 expected: "PostCodeByField neatbilst pasta indeksa formātam valstī, kura norādīta laukā PostCodeCountry",
693 },
694 {
695 ns: "Test.BooleanString",
696 expected: "BooleanString jābūt derīgai boolean vērtībai",
697 },
698 }
699
700 for _, tt := range tests {
701
702 var fe validator.FieldError
703
704 for _, e := range errs {
705 if tt.ns == e.Namespace() {
706 fe = e
707 break
708 }
709 }
710
711 NotEqual(t, fe, nil)
712 Equal(t, tt.expected, fe.Translate(trans))
713 }
714 }
715
View as plain text