From 7422dd4828caf8066fe72718b2acb95968014726 Mon Sep 17 00:00:00 2001 From: Dean Karn Date: Sun, 5 Jul 2015 14:43:14 -0400 Subject: [PATCH 1/4] update latest benchmarks --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4a4cff1..4a22a00 100644 --- a/README.md +++ b/README.md @@ -127,11 +127,11 @@ Benchmarks ```go $ go test -cpu=4 -bench=. -benchmem=true PASS -BenchmarkValidateField-4 3000000 436 ns/op 192 B/op 2 allocs/op -BenchmarkValidateStructSimple-4 500000 2863 ns/op 784 B/op 13 allocs/op -BenchmarkTemplateParallelSimple-4 500000 3044 ns/op 784 B/op 13 allocs/op -BenchmarkValidateStructLarge-4 100000 15226 ns/op 4853 B/op 74 allocs/op -BenchmarkTemplateParallelLarge-4 100000 14637 ns/op 4856 B/op 74 allocs/op +BenchmarkValidateField-4 3000000 429 ns/op 192 B/op 2 allocs/op +BenchmarkValidateStructSimple-4 500000 2877 ns/op 657 B/op 10 allocs/op +BenchmarkTemplateParallelSimple-4 500000 3097 ns/op 657 B/op 10 allocs/op +BenchmarkValidateStructLarge-4 100000 15228 ns/op 4350 B/op 62 allocs/op +BenchmarkTemplateParallelLarge-4 100000 14257 ns/op 4354 B/op 62 allocs/op ``` How to Contribute From c4ae288afde0d7121adee8a0f5fb03ab041d06dc Mon Sep 17 00:00:00 2001 From: The Gitter Badger Date: Mon, 6 Jul 2015 12:00:40 +0000 Subject: [PATCH 2/4] Added Gitter badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 4a22a00..36ac9da 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ Package validator ================ + +[![Join the chat at https://gitter.im/bluesuncorp/validator](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/bluesuncorp/validator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://travis-ci.org/bluesuncorp/validator.svg?branch=v5.1)](https://travis-ci.org/bluesuncorp/validator) [![Coverage Status](https://coveralls.io/repos/bluesuncorp/validator/badge.svg?branch=v5)](https://coveralls.io/r/bluesuncorp/validator?branch=v5) [![GoDoc](https://godoc.org/gopkg.in/bluesuncorp/validator.v5?status.svg)](https://godoc.org/gopkg.in/bluesuncorp/validator.v5) From e1fd32247fdca4ef85661aed75b1d5fbd2bb92ba Mon Sep 17 00:00:00 2001 From: joeybloggs Date: Thu, 9 Jul 2015 14:06:48 -0400 Subject: [PATCH 3/4] Fix interface issue when value is set but no validation tag exists --- validator.go | 2 +- validator_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/validator.go b/validator.go index b2ccb95..ccd2a55 100644 --- a/validator.go +++ b/validator.go @@ -610,7 +610,7 @@ func (v *Validate) fieldWithNameAndValue(val interface{}, current interface{}, f var valueField reflect.Value // This is a double check if coming from validate.Struct but need to be here in case function is called directly - if tag == noValidationTag { + if tag == noValidationTag || tag == "" { return nil } diff --git a/validator_test.go b/validator_test.go index da195dc..1b2e803 100644 --- a/validator_test.go +++ b/validator_test.go @@ -606,6 +606,19 @@ func TestInterfaceErrValidation(t *testing.T) { Equal(t, err.IsPlaceholderErr, false) Equal(t, err.IsSliceOrArray, false) Equal(t, len(err.SliceOrArrayErrs), 0) + + type MyStruct struct { + A, B string + C interface{} + } + + var a MyStruct + + a.A = "value" + a.C = "nu" + + errs = validate.Struct(a) + Equal(t, errs, nil) } func TestMapDiveValidation(t *testing.T) { From 9d2b8ee9d40d85461a06512c6cfbacff9269120d Mon Sep 17 00:00:00 2001 From: joeybloggs Date: Thu, 9 Jul 2015 14:18:54 -0400 Subject: [PATCH 4/4] updated coverage tests to be 100% --- validator_test.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/validator_test.go b/validator_test.go index 1b2e803..8bfff9b 100644 --- a/validator_test.go +++ b/validator_test.go @@ -231,6 +231,18 @@ func AssertMapFieldError(t *testing.T, s map[string]*FieldError, field string, e EqualSkip(t, 2, val.Tag, expectedTag) } +func TestBadKeyValidation(t *testing.T) { + type Test struct { + Name string `validate:"required, "` + } + + tst := &Test{ + Name: "test", + } + + PanicMatches(t, func() { validate.Struct(tst) }, "Invalid validation tag on field Name") +} + func TestFlattenValidation(t *testing.T) { type Inner struct { @@ -623,9 +635,12 @@ func TestInterfaceErrValidation(t *testing.T) { func TestMapDiveValidation(t *testing.T) { + n := map[int]interface{}{0: nil} + err := validate.Field(n, "omitempty,required") + m := map[int]string{0: "ok", 3: "", 4: "ok"} - err := validate.Field(m, "len=3,dive,required") + err = validate.Field(m, "len=3,dive,required") NotEqual(t, err, nil) Equal(t, err.IsPlaceholderErr, true) Equal(t, err.IsMap, true)