|
|
@ -1564,10 +1564,6 @@ func TestCrossNamespaceFieldValidation(t *testing.T) { |
|
|
|
Name string |
|
|
|
Name string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type MapStruct struct { |
|
|
|
|
|
|
|
Name string |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type Inner struct { |
|
|
|
type Inner struct { |
|
|
|
CreatedAt *time.Time |
|
|
|
CreatedAt *time.Time |
|
|
|
Slice []string |
|
|
|
Slice []string |
|
|
@ -1653,10 +1649,10 @@ func TestCrossNamespaceFieldValidation(t *testing.T) { |
|
|
|
Equal(t, kind, reflect.String) |
|
|
|
Equal(t, kind, reflect.String) |
|
|
|
Equal(t, current.String(), "val2") |
|
|
|
Equal(t, current.String(), "val2") |
|
|
|
|
|
|
|
|
|
|
|
current, kind, ok = v.getStructFieldOKInternal(val, "Inner.CrazyNonExistantField") |
|
|
|
current, _, ok = v.getStructFieldOKInternal(val, "Inner.CrazyNonExistantField") |
|
|
|
Equal(t, ok, false) |
|
|
|
Equal(t, ok, false) |
|
|
|
|
|
|
|
|
|
|
|
current, kind, ok = v.getStructFieldOKInternal(val, "Inner.Slice[101]") |
|
|
|
current, _, ok = v.getStructFieldOKInternal(val, "Inner.Slice[101]") |
|
|
|
Equal(t, ok, false) |
|
|
|
Equal(t, ok, false) |
|
|
|
|
|
|
|
|
|
|
|
current, kind, ok = v.getStructFieldOKInternal(val, "Inner.Map[key3]") |
|
|
|
current, kind, ok = v.getStructFieldOKInternal(val, "Inner.Map[key3]") |
|
|
@ -1854,8 +1850,6 @@ func TestSQLValue2Validation(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
PanicMatches(t, func() { validate.Var(val, "required") }, "SQL Driver Valuer error: some kind of error") |
|
|
|
PanicMatches(t, func() { validate.Var(val, "required") }, "SQL Driver Valuer error: some kind of error") |
|
|
|
|
|
|
|
|
|
|
|
type myValuer valuer |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
myVal := valuer{ |
|
|
|
myVal := valuer{ |
|
|
|
Name: "", |
|
|
|
Name: "", |
|
|
|
} |
|
|
|
} |
|
|
@ -1907,8 +1901,6 @@ func TestSQLValueValidation(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
PanicMatches(t, func() { errs = validate.Var(val, "required") }, "SQL Driver Valuer error: some kind of error") |
|
|
|
PanicMatches(t, func() { errs = validate.Var(val, "required") }, "SQL Driver Valuer error: some kind of error") |
|
|
|
|
|
|
|
|
|
|
|
type myValuer valuer |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
myVal := valuer{ |
|
|
|
myVal := valuer{ |
|
|
|
Name: "", |
|
|
|
Name: "", |
|
|
|
} |
|
|
|
} |
|
|
@ -2696,11 +2688,8 @@ func TestBadKeyValidation(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
func TestInterfaceErrValidation(t *testing.T) { |
|
|
|
func TestInterfaceErrValidation(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
var v1 interface{} |
|
|
|
var v2 interface{} = 1 |
|
|
|
var v2 interface{} |
|
|
|
var v1 interface{} = v2 |
|
|
|
|
|
|
|
|
|
|
|
v2 = 1 |
|
|
|
|
|
|
|
v1 = v2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
validate := New() |
|
|
|
validate := New() |
|
|
|
errs := validate.Var(v1, "len=1") |
|
|
|
errs := validate.Var(v1, "len=1") |
|
|
@ -7146,7 +7135,7 @@ func TestValidateStructRegisterCtx(t *testing.T) { |
|
|
|
Equal(t, ctxSlVal, "slVal") |
|
|
|
Equal(t, ctxSlVal, "slVal") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestHostnameValidation(t *testing.T) { |
|
|
|
func TestHostnameRFC952Validation(t *testing.T) { |
|
|
|
tests := []struct { |
|
|
|
tests := []struct { |
|
|
|
param string |
|
|
|
param string |
|
|
|
expected bool |
|
|
|
expected bool |
|
|
@ -7157,6 +7146,7 @@ func TestHostnameValidation(t *testing.T) { |
|
|
|
{"test.example24.com", true}, |
|
|
|
{"test.example24.com", true}, |
|
|
|
{"test24.example24.com", true}, |
|
|
|
{"test24.example24.com", true}, |
|
|
|
{"example", true}, |
|
|
|
{"example", true}, |
|
|
|
|
|
|
|
{"1.foo.com", false}, |
|
|
|
{"test.example.com.", false}, |
|
|
|
{"test.example.com.", false}, |
|
|
|
{"example.com.", false}, |
|
|
|
{"example.com.", false}, |
|
|
|
{"example24.com.", false}, |
|
|
|
{"example24.com.", false}, |
|
|
@ -7178,15 +7168,112 @@ func TestHostnameValidation(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
if test.expected { |
|
|
|
if test.expected { |
|
|
|
if !IsEqual(errs, nil) { |
|
|
|
if !IsEqual(errs, nil) { |
|
|
|
t.Fatalf("Index: %d hostname failed Error: %s", i, errs) |
|
|
|
t.Fatalf("Index: %d hostname failed Error: %v", i, errs) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if IsEqual(errs, nil) { |
|
|
|
|
|
|
|
t.Fatalf("Index: %d hostname failed Error: %v", i, errs) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
val := getError(errs, "", "") |
|
|
|
|
|
|
|
if val.Tag() != "hostname" { |
|
|
|
|
|
|
|
t.Fatalf("Index: %d hostname failed Error: %v", i, errs) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestHostnameRFC1123Validation(t *testing.T) { |
|
|
|
|
|
|
|
tests := []struct { |
|
|
|
|
|
|
|
param string |
|
|
|
|
|
|
|
expected bool |
|
|
|
|
|
|
|
}{ |
|
|
|
|
|
|
|
{"test.example.com", true}, |
|
|
|
|
|
|
|
{"example.com", true}, |
|
|
|
|
|
|
|
{"example24.com", true}, |
|
|
|
|
|
|
|
{"test.example24.com", true}, |
|
|
|
|
|
|
|
{"test24.example24.com", true}, |
|
|
|
|
|
|
|
{"example", true}, |
|
|
|
|
|
|
|
{"1.foo.com", true}, |
|
|
|
|
|
|
|
{"test.example.com.", false}, |
|
|
|
|
|
|
|
{"example.com.", false}, |
|
|
|
|
|
|
|
{"example24.com.", false}, |
|
|
|
|
|
|
|
{"test.example24.com.", false}, |
|
|
|
|
|
|
|
{"test24.example24.com.", false}, |
|
|
|
|
|
|
|
{"example.", false}, |
|
|
|
|
|
|
|
{"192.168.0.1", true}, |
|
|
|
|
|
|
|
{"email@example.com", false}, |
|
|
|
|
|
|
|
{"2001:cdba:0000:0000:0000:0000:3257:9652", false}, |
|
|
|
|
|
|
|
{"2001:cdba:0:0:0:0:3257:9652", false}, |
|
|
|
|
|
|
|
{"2001:cdba::3257:9652", false}, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
validate := New() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for i, test := range tests { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
errs := validate.Var(test.param, "hostname_rfc1123") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if test.expected { |
|
|
|
|
|
|
|
if !IsEqual(errs, nil) { |
|
|
|
|
|
|
|
t.Fatalf("Index: %d hostname failed Error: %v", i, errs) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if IsEqual(errs, nil) { |
|
|
|
|
|
|
|
t.Fatalf("Index: %d hostname failed Error: %v", i, errs) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
val := getError(errs, "", "") |
|
|
|
|
|
|
|
if val.Tag() != "hostname_rfc1123" { |
|
|
|
|
|
|
|
t.Fatalf("Index: %d hostname failed Error: %v", i, errs) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestHostnameRFC1123AliasValidation(t *testing.T) { |
|
|
|
|
|
|
|
tests := []struct { |
|
|
|
|
|
|
|
param string |
|
|
|
|
|
|
|
expected bool |
|
|
|
|
|
|
|
}{ |
|
|
|
|
|
|
|
{"test.example.com", true}, |
|
|
|
|
|
|
|
{"example.com", true}, |
|
|
|
|
|
|
|
{"example24.com", true}, |
|
|
|
|
|
|
|
{"test.example24.com", true}, |
|
|
|
|
|
|
|
{"test24.example24.com", true}, |
|
|
|
|
|
|
|
{"example", true}, |
|
|
|
|
|
|
|
{"1.foo.com", true}, |
|
|
|
|
|
|
|
{"test.example.com.", false}, |
|
|
|
|
|
|
|
{"example.com.", false}, |
|
|
|
|
|
|
|
{"example24.com.", false}, |
|
|
|
|
|
|
|
{"test.example24.com.", false}, |
|
|
|
|
|
|
|
{"test24.example24.com.", false}, |
|
|
|
|
|
|
|
{"example.", false}, |
|
|
|
|
|
|
|
{"192.168.0.1", true}, |
|
|
|
|
|
|
|
{"email@example.com", false}, |
|
|
|
|
|
|
|
{"2001:cdba:0000:0000:0000:0000:3257:9652", false}, |
|
|
|
|
|
|
|
{"2001:cdba:0:0:0:0:3257:9652", false}, |
|
|
|
|
|
|
|
{"2001:cdba::3257:9652", false}, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
validate := New() |
|
|
|
|
|
|
|
validate.RegisterAlias("hostname", "hostname_rfc1123") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for i, test := range tests { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
errs := validate.Var(test.param, "hostname") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if test.expected { |
|
|
|
|
|
|
|
if !IsEqual(errs, nil) { |
|
|
|
|
|
|
|
t.Fatalf("Index: %d hostname failed Error: %v", i, errs) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if IsEqual(errs, nil) { |
|
|
|
if IsEqual(errs, nil) { |
|
|
|
t.Fatalf("Index: %d hostname failed Error: %s", i, errs) |
|
|
|
t.Fatalf("Index: %d hostname failed Error: %v", i, errs) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
val := getError(errs, "", "") |
|
|
|
val := getError(errs, "", "") |
|
|
|
if val.Tag() != "hostname" { |
|
|
|
if val.Tag() != "hostname" { |
|
|
|
t.Fatalf("Index: %d hostname failed Error: %s", i, errs) |
|
|
|
t.Fatalf("Index: %d hostname failed Error: %v", i, errs) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -7226,15 +7313,15 @@ func TestFQDNValidation(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
if test.expected { |
|
|
|
if test.expected { |
|
|
|
if !IsEqual(errs, nil) { |
|
|
|
if !IsEqual(errs, nil) { |
|
|
|
t.Fatalf("Index: %d fqdn failed Error: %s", i, errs) |
|
|
|
t.Fatalf("Index: %d fqdn failed Error: %v", i, errs) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if IsEqual(errs, nil) { |
|
|
|
if IsEqual(errs, nil) { |
|
|
|
t.Fatalf("Index: %d fqdn failed Error: %s", i, errs) |
|
|
|
t.Fatalf("Index: %d fqdn failed Error: %v", i, errs) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
val := getError(errs, "", "") |
|
|
|
val := getError(errs, "", "") |
|
|
|
if val.Tag() != "fqdn" { |
|
|
|
if val.Tag() != "fqdn" { |
|
|
|
t.Fatalf("Index: %d fqdn failed Error: %s", i, errs) |
|
|
|
t.Fatalf("Index: %d fqdn failed Error: %v", i, errs) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|