From 89a590900460b411a8df2f970d2649c6cebc7e32 Mon Sep 17 00:00:00 2001 From: joeybloggs Date: Sat, 4 Jul 2015 14:08:59 -0400 Subject: [PATCH] add test to ensure 100% of the lines of code are called, even in the pool --- .gitignore | 3 ++- validator_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4159020..257a8ca 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,5 @@ _testmain.go *.test *.prof *.test -*.out \ No newline at end of file +*.out +cover.html \ No newline at end of file diff --git a/validator_test.go b/validator_test.go index 1eda6a0..da195dc 100644 --- a/validator_test.go +++ b/validator_test.go @@ -14,6 +14,11 @@ import ( // - Run "gocov test | gocov report" to report on test converage by file // - Run "gocov test | gocov annotate -" to report on all code and functions, those ,marked with "MISS" were never called // +// or +// +// -- may be a good idea to change to output path to somewherelike /tmp +// go test -coverprofile cover.out && go tool cover -html=cover.out -o cover.html +// // // go test -cpuprofile cpu.out // ./validator.test -test.bench=. -test.cpuprofile=cpu.prof @@ -3765,3 +3770,23 @@ func TestInvalidValidatorFunction(t *testing.T) { PanicMatches(t, func() { validate.Field(s.Test, "zzxxBadFunction") }, fmt.Sprintf("Undefined validation function on field %s", "")) } + +func TestPoolObjectMaxSizeValidation(t *testing.T) { + // this will ensure that the pool objects are let go + // when the pool is saturated + validate.SetMaxStructPoolSize(0) + + tSuccess := &TestSlice{ + Required: []int{1}, + Len: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, + Min: []int{1, 2}, + Max: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, + MinMax: []int{1, 2, 3, 4, 5}, + OmitEmpty: []int{}, + } + + for i := 0; i < 2; i++ { + err := validate.Struct(tSuccess) + Equal(t, err, nil) + } +}