Skip to content

Commit 89a5909

Browse files
joeybloggsjoeybloggs
authored andcommitted
add test to ensure 100% of the lines of code are called, even in the pool
1 parent 82abe38 commit 89a5909

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ _testmain.go
2323
*.test
2424
*.prof
2525
*.test
26-
*.out
26+
*.out
27+
cover.html

validator_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import (
1414
// - Run "gocov test | gocov report" to report on test converage by file
1515
// - Run "gocov test | gocov annotate -" to report on all code and functions, those ,marked with "MISS" were never called
1616
//
17+
// or
18+
//
19+
// -- may be a good idea to change to output path to somewherelike /tmp
20+
// go test -coverprofile cover.out && go tool cover -html=cover.out -o cover.html
21+
//
1722
//
1823
// go test -cpuprofile cpu.out
1924
// ./validator.test -test.bench=. -test.cpuprofile=cpu.prof
@@ -3765,3 +3770,23 @@ func TestInvalidValidatorFunction(t *testing.T) {
37653770

37663771
PanicMatches(t, func() { validate.Field(s.Test, "zzxxBadFunction") }, fmt.Sprintf("Undefined validation function on field %s", ""))
37673772
}
3773+
3774+
func TestPoolObjectMaxSizeValidation(t *testing.T) {
3775+
// this will ensure that the pool objects are let go
3776+
// when the pool is saturated
3777+
validate.SetMaxStructPoolSize(0)
3778+
3779+
tSuccess := &TestSlice{
3780+
Required: []int{1},
3781+
Len: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 0},
3782+
Min: []int{1, 2},
3783+
Max: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 0},
3784+
MinMax: []int{1, 2, 3, 4, 5},
3785+
OmitEmpty: []int{},
3786+
}
3787+
3788+
for i := 0; i < 2; i++ {
3789+
err := validate.Struct(tSuccess)
3790+
Equal(t, err, nil)
3791+
}
3792+
}

0 commit comments

Comments
 (0)