From af4caa104acb9d73a63a6bc47210b13295d8c6e7 Mon Sep 17 00:00:00 2001 From: Lucas Mendes Loureiro Date: Fri, 16 Apr 2021 00:07:18 -0300 Subject: [PATCH] implementing validator tests --- go.mod | 5 ++++- go.sum | 6 ++++++ translations/en/en_test.go | 6 ++++++ translations/es/es_test.go | 8 +++++++- translations/fr/fr_test.go | 8 +++++++- translations/id/id_test.go | 8 +++++++- translations/ja/ja_test.go | 8 +++++++- translations/nl/nl_test.go | 8 +++++++- translations/pt/pt_test.go | 6 ++++++ translations/pt_BR/pt_BR_test.go | 8 +++++++- translations/ru/ru_test.go | 6 ++++++ translations/tr/tr_test.go | 8 +++++++- translations/zh/zh_test.go | 6 ++++++ translations/zh_tw/zh_tw_test.go | 6 ++++++ 14 files changed, 89 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 53c4820..f3bc44a 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,9 @@ require ( github.com/go-playground/locales v0.13.0 github.com/go-playground/universal-translator v0.17.0 github.com/leodido/go-urn v1.2.0 + github.com/lucasmendesl/validator v9.31.0+incompatible // indirect golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 - golang.org/x/text v0.3.2 // indirect + golang.org/x/text v0.3.2 + gopkg.in/go-playground/assert.v1 v1.2.1 // indirect + gopkg.in/go-playground/validator.v9 v9.31.0 // indirect ) diff --git a/go.sum b/go.sum index 4b00cf6..3a31e6f 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD87 github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= +github.com/lucasmendesl/validator v9.31.0+incompatible h1:kiNduc38Ha9IcUxU748i/3rhgKYF8QC8n9z9ufrCp+0= +github.com/lucasmendesl/validator v9.31.0+incompatible/go.mod h1:N8FdZMEBYHc9h4qMPmyCfq28BSvnOdmNyflwJA8rw64= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= @@ -29,5 +31,9 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e h1:FDhOuMEY4JVRztM/gsbk+IK golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= +gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= +gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M= +gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/translations/en/en_test.go b/translations/en/en_test.go index 2b113c6..b3c9916 100644 --- a/translations/en/en_test.go +++ b/translations/en/en_test.go @@ -97,6 +97,7 @@ func TestTranslations(t *testing.T) { Excludes string `validate:"excludes=text"` ExcludesAll string `validate:"excludesall=!@#$"` ExcludesRune string `validate:"excludesrune=☻"` + Regex string `validate:"regex=[0-9]"` ISBN string `validate:"isbn"` ISBN10 string `validate:"isbn10"` ISBN13 string `validate:"isbn13"` @@ -182,6 +183,7 @@ func TestTranslations(t *testing.T) { test.ExcludesAll = "This is Great!" test.ExcludesRune = "Love it ☻" + test.Regex = "abctest" test.ASCII = "カタカナ" test.PrintableASCII = "カタカナ" @@ -340,6 +342,10 @@ func TestTranslations(t *testing.T) { ns: "Test.ExcludesAll", expected: "ExcludesAll cannot contain any of the following characters '!@#$'", }, + { + ns: "Test.Regex", + expected: "Regex is not in the correct format", + }, { ns: "Test.ExcludesRune", expected: "ExcludesRune cannot contain the following '☻'", diff --git a/translations/es/es_test.go b/translations/es/es_test.go index 070e3a8..d8fe082 100644 --- a/translations/es/es_test.go +++ b/translations/es/es_test.go @@ -4,9 +4,9 @@ import ( "testing" "time" + . "github.com/go-playground/assert/v2" spanish "github.com/go-playground/locales/es" ut "github.com/go-playground/universal-translator" - . "github.com/go-playground/assert/v2" "github.com/go-playground/validator/v10" ) @@ -97,6 +97,7 @@ func TestTranslations(t *testing.T) { Excludes string `validate:"excludes=text"` ExcludesAll string `validate:"excludesall=!@#$"` ExcludesRune string `validate:"excludesrune=☻"` + Regex string `validate:"regex=[0-9]"` ISBN string `validate:"isbn"` ISBN10 string `validate:"isbn10"` ISBN13 string `validate:"isbn13"` @@ -178,6 +179,7 @@ func TestTranslations(t *testing.T) { test.ExcludesAll = "This is Great!" test.ExcludesRune = "Love it ☻" + test.Regex = "abctest" test.ASCII = "カタカナ" test.PrintableASCII = "カタカナ" @@ -336,6 +338,10 @@ func TestTranslations(t *testing.T) { ns: "Test.ExcludesRune", expected: "ExcludesRune no puede contener lo siguiente '☻'", }, + { + ns: "Test.Regex", + expected: "Regex no tiene el formato correcto", + }, { ns: "Test.ContainsAny", expected: "ContainsAny debe contener al menos uno de los siguientes caracteres '!@#$'", diff --git a/translations/fr/fr_test.go b/translations/fr/fr_test.go index a3f864c..1c700cc 100644 --- a/translations/fr/fr_test.go +++ b/translations/fr/fr_test.go @@ -4,9 +4,9 @@ import ( "testing" "time" + . "github.com/go-playground/assert/v2" french "github.com/go-playground/locales/fr" ut "github.com/go-playground/universal-translator" - . "github.com/go-playground/assert/v2" "github.com/go-playground/validator/v10" ) @@ -97,6 +97,7 @@ func TestTranslations(t *testing.T) { Excludes string `validate:"excludes=text"` ExcludesAll string `validate:"excludesall=!@#$"` ExcludesRune string `validate:"excludesrune=☻"` + Regex string `validate:"regex=[0-9]"` ISBN string `validate:"isbn"` ISBN10 string `validate:"isbn10"` ISBN13 string `validate:"isbn13"` @@ -175,6 +176,7 @@ func TestTranslations(t *testing.T) { test.ExcludesAll = "This is Great!" test.ExcludesRune = "Love it ☻" + test.Regex = "abctest" test.ASCII = "カタカナ" test.PrintableASCII = "カタカナ" @@ -330,6 +332,10 @@ func TestTranslations(t *testing.T) { ns: "Test.ExcludesRune", expected: "ExcludesRune ne doit pas contenir ce qui suit '☻'", }, + { + ns: "Test.Regex", + expected: "Regex n'est pas au bon format", + }, { ns: "Test.ContainsAny", expected: "ContainsAny doit contenir au moins l' un des caractères suivants '!@#$'", diff --git a/translations/id/id_test.go b/translations/id/id_test.go index 83a72aa..f4ef0ce 100644 --- a/translations/id/id_test.go +++ b/translations/id/id_test.go @@ -4,9 +4,9 @@ import ( "testing" "time" + . "github.com/go-playground/assert/v2" indonesia "github.com/go-playground/locales/id" ut "github.com/go-playground/universal-translator" - . "github.com/go-playground/assert/v2" "github.com/go-playground/validator/v10" ) @@ -97,6 +97,7 @@ func TestTranslations(t *testing.T) { Excludes string `validate:"excludes=text"` ExcludesAll string `validate:"excludesall=!@#$"` ExcludesRune string `validate:"excludesrune=☻"` + Regex string `validate:"regex=[0-9]"` ISBN string `validate:"isbn"` ISBN10 string `validate:"isbn10"` ISBN13 string `validate:"isbn13"` @@ -175,6 +176,7 @@ func TestTranslations(t *testing.T) { test.ExcludesAll = "This is Great!" test.ExcludesRune = "Love it ☻" + test.Regex = "abctest" test.ASCII = "カタカナ" test.PrintableASCII = "カタカナ" @@ -330,6 +332,10 @@ func TestTranslations(t *testing.T) { ns: "Test.ExcludesRune", expected: "ExcludesRune tidak boleh berisi '☻'", }, + { + ns: "Test.Regex", + expected: "Format Regex salah", + }, { ns: "Test.ContainsAny", expected: "ContainsAny harus berisi setidaknya salah satu karakter berikut '!@#$'", diff --git a/translations/ja/ja_test.go b/translations/ja/ja_test.go index 0120760..0d4ff35 100644 --- a/translations/ja/ja_test.go +++ b/translations/ja/ja_test.go @@ -4,9 +4,9 @@ import ( "testing" "time" + . "github.com/go-playground/assert/v2" ja_locale "github.com/go-playground/locales/ja" ut "github.com/go-playground/universal-translator" - . "github.com/go-playground/assert/v2" "github.com/go-playground/validator/v10" ) @@ -97,6 +97,7 @@ func TestTranslations(t *testing.T) { Excludes string `validate:"excludes=text"` ExcludesAll string `validate:"excludesall=!@#$"` ExcludesRune string `validate:"excludesrune=☻"` + Regex string `validate:"regex=[0-9]"` ISBN string `validate:"isbn"` ISBN10 string `validate:"isbn10"` ISBN13 string `validate:"isbn13"` @@ -175,6 +176,7 @@ func TestTranslations(t *testing.T) { test.ExcludesAll = "This is Great!" test.ExcludesRune = "Love it ☻" + test.Regex = "abctest" test.ASCII = "カタカナ" test.PrintableASCII = "カタカナ" @@ -330,6 +332,10 @@ func TestTranslations(t *testing.T) { ns: "Test.ExcludesRune", expected: "ExcludesRuneには'☻'を含めることはできません", }, + { + ns: "Test.Regex", + expected: "Regexは正しい形式ではありません", + }, { ns: "Test.ContainsAny", expected: "ContainsAnyは'!@#$'の少なくとも1つを含まなければなりません", diff --git a/translations/nl/nl_test.go b/translations/nl/nl_test.go index 55f5048..9b9aeec 100644 --- a/translations/nl/nl_test.go +++ b/translations/nl/nl_test.go @@ -4,9 +4,9 @@ import ( "testing" "time" + . "github.com/go-playground/assert/v2" english "github.com/go-playground/locales/en" ut "github.com/go-playground/universal-translator" - . "github.com/go-playground/assert/v2" "github.com/go-playground/validator/v10" ) @@ -97,6 +97,7 @@ func TestTranslations(t *testing.T) { Excludes string `validate:"excludes=text"` ExcludesAll string `validate:"excludesall=!@#$"` ExcludesRune string `validate:"excludesrune=☻"` + Regex string `validate:"regex=[0-9]"` ISBN string `validate:"isbn"` ISBN10 string `validate:"isbn10"` ISBN13 string `validate:"isbn13"` @@ -175,6 +176,7 @@ func TestTranslations(t *testing.T) { test.ExcludesAll = "This is Great!" test.ExcludesRune = "Love it ☻" + test.Regex = "abctest" test.ASCII = "カタカナ" test.PrintableASCII = "カタカナ" @@ -330,6 +332,10 @@ func TestTranslations(t *testing.T) { ns: "Test.ExcludesRune", expected: "ExcludesRune mag niet het volgende bevatten '☻'", }, + { + ns: "Test.Regex", + expected: "Regex is not in the correct format", + }, { ns: "Test.ContainsAny", expected: "ContainsAny moet tenminste een van de volgende karakters bevatten '!@#$'", diff --git a/translations/pt/pt_test.go b/translations/pt/pt_test.go index ceec15f..6a0381a 100644 --- a/translations/pt/pt_test.go +++ b/translations/pt/pt_test.go @@ -98,6 +98,7 @@ func TestTranslations(t *testing.T) { Excludes string `validate:"excludes=text"` ExcludesAll string `validate:"excludesall=!@#$"` ExcludesRune string `validate:"excludesrune=☻"` + Regex string `validate:"regex=[0-9]"` ISBN string `validate:"isbn"` ISBN10 string `validate:"isbn10"` ISBN13 string `validate:"isbn13"` @@ -183,6 +184,7 @@ func TestTranslations(t *testing.T) { test.ExcludesAll = "This is Great!" test.ExcludesRune = "Love it ☻" + test.Regex = "abctest" test.ASCII = "カタカナ" test.PrintableASCII = "カタカナ" @@ -345,6 +347,10 @@ func TestTranslations(t *testing.T) { ns: "Test.ExcludesRune", expected: "ExcludesRune não pode conter o seguinte '☻'", }, + { + ns: "Test.Regex", + expected: "Regex não está no formato correto", + }, { ns: "Test.ContainsAny", expected: "ContainsAny deve conter pelo menos um dos seguintes caracteres '!@#$'", diff --git a/translations/pt_BR/pt_BR_test.go b/translations/pt_BR/pt_BR_test.go index 32125f6..c25dcb4 100644 --- a/translations/pt_BR/pt_BR_test.go +++ b/translations/pt_BR/pt_BR_test.go @@ -4,10 +4,10 @@ import ( "testing" "time" + . "github.com/go-playground/assert/v2" brazilian_portuguese "github.com/go-playground/locales/pt_BR" ut "github.com/go-playground/universal-translator" "github.com/go-playground/validator/v10" - . "github.com/go-playground/assert/v2" ) func TestTranslations(t *testing.T) { @@ -97,6 +97,7 @@ func TestTranslations(t *testing.T) { Excludes string `validate:"excludes=text"` ExcludesAll string `validate:"excludesall=!@#$"` ExcludesRune string `validate:"excludesrune=☻"` + Regex string `validate:"regex=[0-9]"` ISBN string `validate:"isbn"` ISBN10 string `validate:"isbn10"` ISBN13 string `validate:"isbn13"` @@ -175,6 +176,7 @@ func TestTranslations(t *testing.T) { test.ExcludesAll = "Isso é Ótimo!" test.ExcludesRune = "Amo isso ☻" + test.Regex = "abctest" test.ASCII = "カタカナ" test.PrintableASCII = "カタカナ" @@ -330,6 +332,10 @@ func TestTranslations(t *testing.T) { ns: "Test.ExcludesRune", expected: "ExcludesRune não deve conter '☻'", }, + { + ns: "Test.Regex", + expected: "Regex não está no formato correto", + }, { ns: "Test.ContainsAny", expected: "ContainsAny deve conter pelo menos um dos caracteres '!@#$'", diff --git a/translations/ru/ru_test.go b/translations/ru/ru_test.go index aa5beb7..2e3a04c 100644 --- a/translations/ru/ru_test.go +++ b/translations/ru/ru_test.go @@ -99,6 +99,7 @@ func TestTranslations(t *testing.T) { Excludes string `validate:"excludes=text"` ExcludesAll string `validate:"excludesall=!@#$"` ExcludesRune string `validate:"excludesrune=☻"` + Regex string `validate:"regex=[0-9]"` ISBN string `validate:"isbn"` ISBN10 string `validate:"isbn10"` ISBN13 string `validate:"isbn13"` @@ -180,6 +181,7 @@ func TestTranslations(t *testing.T) { test.ExcludesAll = "This is Great!" test.ExcludesRune = "Love it ☻" + test.Regex = "abctest" test.ASCII = "カタカナ" test.PrintableASCII = "カタカナ" @@ -338,6 +340,10 @@ func TestTranslations(t *testing.T) { ns: "Test.ExcludesRune", expected: "ExcludesRune не должен содержать '☻'", }, + { + ns: "Test.Regex", + expected: "Regex имеет неправильный формат", + }, { ns: "Test.ContainsAny", expected: "ContainsAny должен содержать минимум один из символов '!@#$'", diff --git a/translations/tr/tr_test.go b/translations/tr/tr_test.go index 7cfa5a4..d9daf3d 100644 --- a/translations/tr/tr_test.go +++ b/translations/tr/tr_test.go @@ -4,9 +4,9 @@ import ( "testing" "time" + . "github.com/go-playground/assert/v2" turkish "github.com/go-playground/locales/tr" ut "github.com/go-playground/universal-translator" - . "github.com/go-playground/assert/v2" "github.com/go-playground/validator/v10" ) @@ -97,6 +97,7 @@ func TestTranslations(t *testing.T) { Excludes string `validate:"excludes=text"` ExcludesAll string `validate:"excludesall=!@#$"` ExcludesRune string `validate:"excludesrune=☻"` + Regex string `validate:"regex=[0-9]"` ISBN string `validate:"isbn"` ISBN10 string `validate:"isbn10"` ISBN13 string `validate:"isbn13"` @@ -178,6 +179,7 @@ func TestTranslations(t *testing.T) { test.ExcludesAll = "This is Great!" test.ExcludesRune = "Love it ☻" + test.Regex = "abctest" test.ASCII = "カタカナ" test.PrintableASCII = "カタカナ" @@ -336,6 +338,10 @@ func TestTranslations(t *testing.T) { ns: "Test.ExcludesRune", expected: "ExcludesRune, '☻' ifadesini içeremez", }, + { + ns: "Test.Regex", + expected: "Regex doğru biçimde değil", + }, { ns: "Test.ContainsAny", expected: "ContainsAny, '!@#$' karakterlerinden en az birini içermelidir", diff --git a/translations/zh/zh_test.go b/translations/zh/zh_test.go index d106e0d..50f2d08 100644 --- a/translations/zh/zh_test.go +++ b/translations/zh/zh_test.go @@ -97,6 +97,7 @@ func TestTranslations(t *testing.T) { Excludes string `validate:"excludes=text"` ExcludesAll string `validate:"excludesall=!@#$"` ExcludesRune string `validate:"excludesrune=☻"` + Regex string `validate:"regex=[0-9]"` ISBN string `validate:"isbn"` ISBN10 string `validate:"isbn10"` ISBN13 string `validate:"isbn13"` @@ -179,6 +180,7 @@ func TestTranslations(t *testing.T) { test.ExcludesAll = "This is Great!" test.ExcludesRune = "Love it ☻" + test.Regex = "abctest" test.ASCII = "カタカナ" test.PrintableASCII = "カタカナ" @@ -341,6 +343,10 @@ func TestTranslations(t *testing.T) { ns: "Test.ExcludesRune", expected: "ExcludesRune不能包含'☻'", }, + { + ns: "Test.Regex", + expected: "Regex的格式不正確", + }, { ns: "Test.ContainsAny", expected: "ContainsAny必须包含至少一个以下字符'!@#$'", diff --git a/translations/zh_tw/zh_tw_test.go b/translations/zh_tw/zh_tw_test.go index cf60d1d..048fb66 100644 --- a/translations/zh_tw/zh_tw_test.go +++ b/translations/zh_tw/zh_tw_test.go @@ -97,6 +97,7 @@ func TestTranslations(t *testing.T) { Excludes string `validate:"excludes=text"` ExcludesAll string `validate:"excludesall=!@#$"` ExcludesRune string `validate:"excludesrune=☻"` + Regex string `validate:"regex=[0-9]"` ISBN string `validate:"isbn"` ISBN10 string `validate:"isbn10"` ISBN13 string `validate:"isbn13"` @@ -176,6 +177,7 @@ func TestTranslations(t *testing.T) { test.ExcludesAll = "This is Great!" test.ExcludesRune = "Love it ☻" + test.Regex = "abctest" test.ASCII = "カタカナ" test.PrintableASCII = "カタカナ" @@ -333,6 +335,10 @@ func TestTranslations(t *testing.T) { ns: "Test.ExcludesRune", expected: "ExcludesRune不能包含'☻'", }, + { + ns: "Test.Regex", + expected: "Regex的格式不正確", + }, { ns: "Test.ContainsAny", expected: "ContainsAny必須包含至少一個以下字元'!@#$'",