MCPcopy Create free account
hub / github.com/go-playground/validator / TestValidate_ValidateMapCtxWithKeys

Function TestValidate_ValidateMapCtxWithKeys

validator_test.go:14754–14826  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14752}
14753
14754func TestValidate_ValidateMapCtxWithKeys(t *testing.T) {
14755 type args struct {
14756 data map[string]interface{}
14757 rules map[string]interface{}
14758 errors map[string]interface{}
14759 }
14760 tests := []struct {
14761 name string
14762 args args
14763 want int
14764 }{
14765 {
14766 name: "test invalid email",
14767 args: args{
14768 data: map[string]interface{}{
14769 "email": "emailaddress",
14770 },
14771 rules: map[string]interface{}{
14772 "email": "required,email",
14773 },
14774 errors: map[string]interface{}{
14775 "email": "Key: 'email' Error:Field validation for 'email' failed on the 'email' tag",
14776 },
14777 },
14778 want: 1,
14779 },
14780 {
14781 name: "test multiple errors with capitalized keys",
14782 args: args{
14783 data: map[string]interface{}{
14784 "Email": "emailaddress",
14785 "Age": 15,
14786 },
14787 rules: map[string]interface{}{
14788 "Email": "required,email",
14789 "Age": "number,gt=16",
14790 },
14791 errors: map[string]interface{}{
14792 "Email": "Key: 'Email' Error:Field validation for 'Email' failed on the 'email' tag",
14793 "Age": "Key: 'Age' Error:Field validation for 'Age' failed on the 'gt' tag",
14794 },
14795 },
14796 want: 2,
14797 },
14798 {
14799 name: "test valid map data",
14800 args: args{
14801 data: map[string]interface{}{
14802 "email": "email@example.com",
14803 "age": 17,
14804 },
14805 rules: map[string]interface{}{
14806 "email": "required,email",
14807 "age": "number,gt=16",
14808 },
14809 errors: map[string]interface{}{},
14810 },
14811 want: 0,

Callers

nothing calls this directly

Calls 3

NewFunction · 0.85
ValidateMapCtxMethod · 0.80
ErrorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…