File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package validator
2+
3+ import "testing"
4+
5+ type BenchTestStruct struct {
6+ Name string `json:"name" constraints:"required=true,nillable=true,min-length=5"`
7+ Age int `json:"age" constraints:"required=true,nillable=true,min=21"`
8+ Description string `json:"description" constraints:"required=true,nillable=true,max-length=50"`
9+ Cost float64 `json:"cost" constraints:"required=true,nillable=true,exclusiveMin=200"`
10+ ItemCount int `json:"itemCount" constraints:"required=true,nillable=true,multipleOf=5"`
11+ }
12+
13+ func BenchmarkValidator (b * testing.B ) {
14+ msg := BenchTestStruct {
15+ Name : "BenchTest" ,
16+ Age : 25 ,
17+ Description : "this is bench testing" ,
18+ Cost : 299.9 ,
19+ ItemCount : 2000 ,
20+ }
21+ sv := NewStructValidator ()
22+ for i := 0 ; i < b .N ; i ++ {
23+ if err := sv .Validate (msg ); err != nil {
24+ b .Errorf ("Error in validation: %s" , err )
25+ }
26+ }
27+ }
Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ func (sv *StructValidator) deepFields(itr interface{}) error {
7171 default :
7272 tag := v .Tag .Get ("constraints" )
7373 if tag == "" {
74- logger .InfoF ("constraint not present, skip to next field" )
74+ logger .InfoF ("constraint not present for field : %s , skip to next field" , v . Name )
7575 continue
7676 }
7777 constraints := parseTag (tag )
Original file line number Diff line number Diff line change @@ -289,6 +289,7 @@ func TestNested(t *testing.T) {
289289
290290/**
291291Empty Struct Validation
292+ // TODO
292293*/
293294
294295type EmptyExample struct {
@@ -303,3 +304,19 @@ func TestEmptyStruct(t *testing.T) {
303304 }
304305
305306}
307+
308+ type ConstExample struct {
309+ Summary string `json:"summary"`
310+ Description string `json:"description" constraints:"required=false,nillable=false"`
311+ }
312+
313+ func TestConstStruct (t * testing.T ) {
314+ msg := ConstExample {
315+ Summary : "testing" ,
316+ Description : "this is testing" ,
317+ }
318+ sv := validator .NewStructValidator ()
319+ if err := sv .Validate (msg ); err != nil {
320+ t .Errorf ("Error in validation: %s" , err )
321+ }
322+ }
You can’t perform that action at this time.
0 commit comments