Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random error in validating required fields, returning error for only one field #284

Open
tigoCaval opened this issue Jan 30, 2025 · 0 comments
Assignees

Comments

@tigoCaval
Copy link

System (please complete the following information):

  • OS: linux
  • GO Version: 1.23.2
  • Pkg Version: 1.5.4

Describe the bug

I'm trying to use the Gookit Validate library to validate input data with required field rules, but I'm encountering an issue: when running the test that validates the "name", "email", and "phone" fields as required, the validation returns errors randomly. In some test runs, the error is returned for the "name" field, in others for the "email" field, and in others for the "phone" field. Below is the test code I'm using:

To Reproduce

func TestValidateData(t *testing.T) {
	rules := map[string]string{
		"name":  "required",
		"email": "required",
		"phone": "required",
	}
	data := map[string]any{}

	v := New(data)
	v.StringRules(rules)

	if !v.Validate() {
		fmt.Println(v.Errors)
	}

	assert.Contains(t, v.Errors.All(), "name")
	assert.Contains(t, v.Errors.All(), "email")
	assert.Contains(t, v.Errors.All(), "phone")
	assert.Error(t, v.Errors)
}

Expected behavior

The expected behavior is that the validator should return errors for all the required fields that are missing ("name", "email", and "phone"). That is, the test should pass by checking that errors are returned for all the required fields.

Screenshots

Descrição da imagem

Additional context

Add any other context about the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants