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

HTTP Pact with root json array fails when using unordered array matching #1631

Open
jakobmagiera opened this issue Nov 1, 2022 · 4 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@jakobmagiera
Copy link

jakobmagiera commented Nov 1, 2022

I have a reproducible case where the pact specifies a request body as follows:

.body(
  newJsonArrayUnordered(
		  refs ->
				  refs.object(
						  ref ->
								  ref.stringType(
										  "id", "123")))
		  .build())

The consumer test looks like this:

HttpResponse response = Request.post(mockServer.getUrl() + "/passIdArray").bodyString("""
				[{"id":"123"}]""", ContentType.APPLICATION_JSON).execute().returnResponse();
		assertEquals(response.getCode(), 200);

This test fails (with an unhelpful Internal Server Error, but that's another issue), but the ordered variant passes.

I debugged this down to matchEqualsIgnoreOrder and then the matchEquality fallback. This ends up comparing two byte arrays (which contain the json content) with equals instead of Arrays.equals(), resulting in a false result even though the arrays are equal by content. See the attached zip for a fully functional gradle project to reproduce the effect.

PactTestArrayFailure.zip

@piotrkrokowski
Copy link

piotrkrokowski commented Nov 3, 2022

Hello. I've got the same issue. After upgrading from au.com.dius.pact.provider:junit5 from 4.3.15 to 4.3.16, some tests started failing.

After some debugging I was able to narrow down the case to MatcherExecutor.matchEqualsIgnoreOrder which apparently receives byte[] arrays as expected and actual, but defines no matchers for that type and falls back to matchEquality, as @jakobmagiera described above.

Please let me know if you need any more details.

@k-boyle
Copy link

k-boyle commented Dec 5, 2022

Hello, updating from 4.3.15 introduces this for us too

@rholshausen rholshausen added the bug Indicates an unexpected problem or unintended behavior label Jan 4, 2023
@rholshausen
Copy link
Contributor

/jira ticket

@github-actions
Copy link

github-actions bot commented Jan 4, 2023

👋 Thanks, Jira [PACT-476] ticket created.

rholshausen added a commit that referenced this issue Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

4 participants