@@ -792,7 +792,7 @@ func TestStructPartial(t *testing.T) {
792792
793793 // the following should all return no errors as everything is valid in
794794 // the default state
795- errs := validate .StructPartialCtx (context . Background (), tPartial , p1 ... )
795+ errs := validate .StructPartialCtx (t . Context (), tPartial , p1 ... )
796796 Equal (t , errs , nil )
797797
798798 errs = validate .StructPartial (tPartial , p2 ... )
@@ -802,7 +802,7 @@ func TestStructPartial(t *testing.T) {
802802 errs = validate .StructPartial (tPartial .SubSlice [0 ], p3 ... )
803803 Equal (t , errs , nil )
804804
805- errs = validate .StructExceptCtx (context . Background (), tPartial , p1 ... )
805+ errs = validate .StructExceptCtx (t . Context (), tPartial , p1 ... )
806806 Equal (t , errs , nil )
807807
808808 errs = validate .StructExcept (tPartial , p2 ... )
@@ -1040,7 +1040,7 @@ func TestCrossStructLteFieldValidation(t *testing.T) {
10401040 AssertError (t , errs , "Test.Float" , "Test.Float" , "Float" , "Float" , "ltecsfield" )
10411041 AssertError (t , errs , "Test.Array" , "Test.Array" , "Array" , "Array" , "ltecsfield" )
10421042
1043- errs = validate .VarWithValueCtx (context . Background (), 1 , "" , "ltecsfield" )
1043+ errs = validate .VarWithValueCtx (t . Context (), 1 , "" , "ltecsfield" )
10441044 NotEqual (t , errs , nil )
10451045 AssertError (t , errs , "" , "" , "" , "" , "ltecsfield" )
10461046
@@ -2233,7 +2233,7 @@ func TestSQLValue2Validation(t *testing.T) {
22332233 AssertError (t , errs , "" , "" , "" , "" , "required" )
22342234
22352235 val .Name = "Valid Name"
2236- errs = validate .VarCtx (context . Background (), val , "required" )
2236+ errs = validate .VarCtx (t . Context (), val , "required" )
22372237 Equal (t , errs , nil )
22382238
22392239 val .Name = "errorme"
@@ -2975,8 +2975,12 @@ func TestUnixDomainSocketExistsValidation(t *testing.T) {
29752975 if err != nil {
29762976 t .Fatalf ("Failed to create test socket: %v" , err )
29772977 }
2978- defer listener .Close ()
2979- defer os .Remove (sockPath )
2978+ defer func () {
2979+ _ = listener .Close ()
2980+ }()
2981+ defer func () {
2982+ _ = os .Remove (sockPath )
2983+ }()
29802984
29812985 // Test with existing socket - should pass
29822986 errs = validate .Var (sockPath , "uds_exists" )
@@ -2987,7 +2991,9 @@ func TestUnixDomainSocketExistsValidation(t *testing.T) {
29872991 if err := os .WriteFile (regularFile , []byte ("test" ), 0644 ); err != nil {
29882992 t .Fatalf ("Failed to create regular file: %v" , err )
29892993 }
2990- defer os .Remove (regularFile )
2994+ defer func () {
2995+ _ = os .Remove (regularFile )
2996+ }()
29912997
29922998 errs = validate .Var (regularFile , "uds_exists" )
29932999 NotEqual (t , errs , nil )
@@ -2998,7 +3004,9 @@ func TestUnixDomainSocketExistsValidation(t *testing.T) {
29983004 if err := os .Mkdir (dirPath , 0755 ); err != nil && ! os .IsExist (err ) {
29993005 t .Fatalf ("Failed to create directory: %v" , err )
30003006 }
3001- defer os .RemoveAll (dirPath )
3007+ defer func () {
3008+ _ = os .RemoveAll (dirPath )
3009+ }()
30023010
30033011 errs = validate .Var (dirPath , "uds_exists" )
30043012 NotEqual (t , errs , nil )
@@ -3015,7 +3023,9 @@ func TestUnixDomainSocketExistsValidation(t *testing.T) {
30153023 if err != nil {
30163024 t .Fatalf ("Failed to create abstract socket: %v" , err )
30173025 }
3018- defer abstractListener .Close ()
3026+ defer func () {
3027+ _ = abstractListener .Close ()
3028+ }()
30193029
30203030 // Test with existing abstract socket - should pass
30213031 errs = validate .Var (abstractSockName , "uds_exists" )
@@ -9830,7 +9840,7 @@ func TestStructFiltered(t *testing.T) {
98309840
98319841 // the following should all return no errors as everything is valid in
98329842 // the default state
9833- errs := validate .StructFilteredCtx (context . Background (), tPartial , p1 )
9843+ errs := validate .StructFilteredCtx (t . Context (), tPartial , p1 )
98349844 Equal (t , errs , nil )
98359845
98369846 errs = validate .StructFiltered (tPartial , p2 )
@@ -10243,7 +10253,7 @@ func TestValidateStructRegisterCtx(t *testing.T) {
1024310253
1024410254 validate .RegisterStructValidationCtx (slFn , Test {})
1024510255
10246- ctx := context .WithValue (context . Background (), & ctxVal , "testval" )
10256+ ctx := context .WithValue (t . Context (), & ctxVal , "testval" )
1024710257 ctx = context .WithValue (ctx , & ctxSlVal , "slVal" )
1024810258 errs := validate .StructCtx (ctx , tst )
1024910259 Equal (t , errs , nil )
@@ -13678,7 +13688,7 @@ func TestValidate_ValidateMapCtx(t *testing.T) {
1367813688 for _ , tt := range tests {
1367913689 t .Run (tt .name , func (t * testing.T ) {
1368013690 validate := New ()
13681- if got := validate .ValidateMapCtx (context . Background (), tt .args .data , tt .args .rules ); len (got ) != tt .want {
13691+ if got := validate .ValidateMapCtx (t . Context (), tt .args .data , tt .args .rules ); len (got ) != tt .want {
1368213692 t .Errorf ("ValidateMapCtx() = %v, want %v" , got , tt .want )
1368313693 }
1368413694 })
@@ -13749,7 +13759,7 @@ func TestValidate_ValidateMapCtxWithKeys(t *testing.T) {
1374913759 for _ , tt := range tests {
1375013760 t .Run (tt .name , func (t * testing.T ) {
1375113761 validate := New ()
13752- errs := validate .ValidateMapCtx (context . Background (), tt .args .data , tt .args .rules )
13762+ errs := validate .ValidateMapCtx (t . Context (), tt .args .data , tt .args .rules )
1375313763 NotEqual (t , errs , nil )
1375413764 Equal (t , len (errs ), tt .want )
1375513765 for key , err := range errs {
@@ -13771,7 +13781,7 @@ func TestValidate_VarWithKey(t *testing.T) {
1377113781
1377213782func TestValidate_VarWithKeyCtx (t * testing.T ) {
1377313783 validate := New ()
13774- errs := validate .VarWithKeyCtx (context . Background (), "age" , 15 , "required,gt=16" )
13784+ errs := validate .VarWithKeyCtx (t . Context (), "age" , 15 , "required,gt=16" )
1377513785 NotEqual (t , errs , nil )
1377613786 AssertError (t , errs , "age" , "age" , "age" , "age" , "gt" )
1377713787
0 commit comments