(t *testing.T)
| 10894 | } |
| 10895 | |
| 10896 | func TestValidateStructRegisterCtx(t *testing.T) { |
| 10897 | var ctxVal string |
| 10898 | |
| 10899 | fnCtx := func(ctx context.Context, fl FieldLevel) bool { |
| 10900 | ctxVal = ctx.Value(&ctxVal).(string) |
| 10901 | return true |
| 10902 | } |
| 10903 | |
| 10904 | var ctxSlVal string |
| 10905 | slFn := func(ctx context.Context, sl StructLevel) { |
| 10906 | ctxSlVal = ctx.Value(&ctxSlVal).(string) |
| 10907 | } |
| 10908 | |
| 10909 | type Test struct { |
| 10910 | Field string `validate:"val"` |
| 10911 | } |
| 10912 | |
| 10913 | var tst Test |
| 10914 | |
| 10915 | validate := New() |
| 10916 | err := validate.RegisterValidationCtx("val", fnCtx) |
| 10917 | Equal(t, err, nil) |
| 10918 | |
| 10919 | validate.RegisterStructValidationCtx(slFn, Test{}) |
| 10920 | |
| 10921 | ctx := context.WithValue(context.Background(), &ctxVal, "testval") |
| 10922 | ctx = context.WithValue(ctx, &ctxSlVal, "slVal") |
| 10923 | errs := validate.StructCtx(ctx, tst) |
| 10924 | Equal(t, errs, nil) |
| 10925 | Equal(t, ctxVal, "testval") |
| 10926 | Equal(t, ctxSlVal, "slVal") |
| 10927 | } |
| 10928 | |
| 10929 | func TestHostnameRFC952Validation(t *testing.T) { |
| 10930 | tests := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…