From 0482874b86ffbffda291b855d8a77fe5021f5126 Mon Sep 17 00:00:00 2001 From: Leonardo Di Donato Date: Tue, 4 Dec 2018 10:35:01 +0100 Subject: [PATCH] Update: Rename urn tag into urn_rfc2141 Signed-off-by: Leonardo Di Donato --- baked_in.go | 6 +++--- validator_test.go | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/baked_in.go b/baked_in.go index 1fd3743..2a086fd 100644 --- a/baked_in.go +++ b/baked_in.go @@ -99,7 +99,7 @@ var ( "email": isEmail, "url": isURL, "uri": isURI, - "urn": isURN, // RFC 2141 + "urn_rfc2141": isUrnRFC2141, // RFC 2141 "file": isFile, "base64": isBase64, "base64url": isBase64URL, @@ -1079,8 +1079,8 @@ func isURL(fl FieldLevel) bool { panic(fmt.Sprintf("Bad field type %T", field.Interface())) } -// isUrn is the validation function for validating if the current field's value is a valid URN as per RFC 2141. -func isURN(fl FieldLevel) bool { +// isUrnRFC2141 is the validation function for validating if the current field's value is a valid URN as per RFC 2141. +func isUrnRFC2141(fl FieldLevel) bool { field := fl.Field() switch field.Kind() { diff --git a/validator_test.go b/validator_test.go index a9bcb54..7213d9b 100644 --- a/validator_test.go +++ b/validator_test.go @@ -5748,7 +5748,7 @@ func TestIsLte(t *testing.T) { NotEqual(t, errs, nil) } -func TestUrn(t *testing.T) { +func TestUrnRFC2141(t *testing.T) { var tests = []struct { param string @@ -5797,11 +5797,13 @@ func TestUrn(t *testing.T) { {"urn:", false}, } + tag := "urn_rfc2141" + validate := New() for i, test := range tests { - errs := validate.Var(test.param, "urn") + errs := validate.Var(test.param, tag) if test.expected { if !IsEqual(errs, nil) { @@ -5812,7 +5814,7 @@ func TestUrn(t *testing.T) { t.Fatalf("Index: %d URN failed Error: %s", i, errs) } else { val := getError(errs, "", "") - if val.Tag() != "urn" { + if val.Tag() != tag { t.Fatalf("Index: %d URN failed Error: %s", i, errs) } } @@ -5820,7 +5822,7 @@ func TestUrn(t *testing.T) { } i := 1 - PanicMatches(t, func() { validate.Var(i, "urn") }, "Bad field type int") + PanicMatches(t, func() { validate.Var(i, tag) }, "Bad field type int") } func TestUrl(t *testing.T) {