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

Mocks are skipped if path is not found in JSONPath #63

Open
nixxxon opened this issue Jul 7, 2024 · 0 comments
Open

Mocks are skipped if path is not found in JSONPath #63

nixxxon opened this issue Jul 7, 2024 · 0 comments

Comments

@nixxxon
Copy link

nixxxon commented Jul 7, 2024

Describe the bug
JSONPath returns error if path is not found which breaks the loop in findMockForRequest, skipping the rest of the mocks.

To Reproduce
Steps to reproduce the behavior:

  1. Create two POST mocks with different paths and JSONPath.
  2. Send two requests with different json-payload.

My mocks look like this:

srv.Mocha.AddMocks(
	mocha.Post(expect.URLPath("/document/edit")).
		Body(
			expect.JSONPath("document_id", expect.ToEqual(float64(1337))),
		))

srv.Mocha.AddMocks(
	mocha.Post(expect.URLPath("/party/edit")).
		Body(
			expect.JSONPath("party_id", expect.ToEqual(float64(1337))),
		))

Expected behavior
The test should succeed, both mocks should be tested. Instead, the second mock is not tested since the second request fails on the first mock. Why is the first mock tested even if the request path does not match with the second request?

Additional context
Returning nil instead of err here https://github.com/vitorsalgado/mocha/blob/3.x/expect/jsonpath.go#L22 fixes my tests.

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

1 participant