Update: Rename urn tag into urn_rfc2141

Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
pull/429/head
Leonardo Di Donato 6 years ago
parent c5423e4116
commit 0482874b86
No known key found for this signature in database
GPG Key ID: BFFB24490FD2E91F
  1. 6
      baked_in.go
  2. 10
      validator_test.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() {

@ -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) {

Loading…
Cancel
Save