João Luiz Vieira
06/22/2022, 7:35 PMtestImplementation('au.com.dius.pact:consumer:4.3.9')
testImplementation('au.com.dius.pact.consumer:junit:4.3.9'
And creating two interactions for the same consumer and provider (one POST and other PUT).
I am setting the same response header for both of the interactions but the second interaction, the response.headers
are being generated different from what I am setting it.
I am setting responseHeaders.put("Content-Type", "application/json; charset=utf-8");
. The first interaction, the header is "Content-Type": "application/json; charset=utf-8",
but in the second it is "Content-Type": "application/json;charset=utf-8"
the difference being that the second there is no space after the ;
.
I added another header just for testing and in the second interaction it added an =
at the end.
Basically, I want that the space in "application/json; charset=utf-8"
is not removed in second interaction. Do you what can I do to achieve this? I am not sure if I am doing something wrong or is some kind of bug.
(code and image in the thread)João Luiz Vieira
06/22/2022, 7:35 PM@Pact(consumer = "config-api", provider = "file-service")
public RequestResponsePact createFileFragment(PactDslWithProvider builder)
{
Map<String, String> requestHeaders = createRequestHeaders();
Map<String, String> responseHeaders = createResponseHeaders();
PactDslJsonBody requestBody = new PactDslJsonBody()
.uuid("clientId", "2454ad95-0352-4494-9a40-6afb333959e4");
PactDslJsonBody responseBody = new PactDslJsonBody()
.uuid("clientId", "2454ad95-0352-4494-9a40-6afb333959e4");
return builder
.given("a file does not exists")
.uponReceiving("create file")
.method("POST").headers(requestHeaders).body(requestBody)
.matchPath("/files")
.willRespondWith()
.status(201).headers(responseHeaders).body(responseBody)
.toPact();
}
@Pact(consumer = "config-api", provider = "file-service")
public RequestResponsePact updateFileFragment(PactDslWithProvider builder)
{
Map<String, String> requestHeaders = createRequestHeaders();
Map<String, String> responseHeaders = createResponseHeaders();
PactDslJsonBody requestBody = new PactDslJsonBody()
.uuid("clientId", "2454ad95-0352-4494-9a40-6afb333959e4");
PactDslJsonBody responseBody = new PactDslJsonBody()
.uuid("clientId", "2454ad95-0352-4494-9a40-6afb333959e4");
String uuidRegex = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
return builder.given("a file exists").
uponReceiving("update the file")
.method("PUT").headers(requestHeaders).body(requestBody)
.matchPath("/files/" + uuidRegex)
.willRespondWith()
.status(200).headers(responseHeaders).body(responseBody)
.toPact();
}
private Map<String, String> createResponseHeaders()
{
Map<String, String> responseHeaders = new HashMap<>();
responseHeaders.put("Content-Type", "application/json; charset=utf-8");
responseHeaders.put("X-Type", "test1; test2");
return responseHeaders;
}
private Map<String, String> createRequestHeaders()
{
Map<String, String> requestHeaders = new HashMap<>();
requestHeaders.put("Content-Type", "application/json");
return requestHeaders;
}
João Luiz Vieira
06/22/2022, 7:36 PMJoão Luiz Vieira
06/22/2022, 7:36 PMresponse.headers
difference in the second interaction (removes the spaces, and added an =
)João Luiz Vieira
06/22/2022, 7:37 PMTimothy Jones
06/23/2022, 12:57 AMJoão Luiz Vieira
06/23/2022, 1:54 AMExpected header "Content-Type" to equal "application/json;charset=utf-8", but was "application/json; charset=utf-8"
. My provider is running on node with the "@pact-foundation/pact": "^9.17.3"
. I thought the problem was in the consumer, but seems to be in the provider as it should(?) consider both values the same.Matt (pactflow.io / pact-js / pact-go)
3
as the specification, but Pact JS core (the version you linked) only supports 2. I’m not sure if you downcast the consumer test to explicitly produce a v2 pact if that will fix itMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Timothy Jones
06/23/2022, 2:38 AMTimothy Jones
06/23/2022, 2:38 AMTimothy Jones
06/23/2022, 2:39 AMJoão Luiz Vieira
06/23/2022, 2:50 AMV3
but changed the consumer generation to V2
and it generated the same thing as before, where the second interaction had a different header value without the space .João Luiz Vieira
06/23/2022, 2:52 AMJoão Luiz Vieira
06/23/2022, 2:52 AMTimothy Jones
06/23/2022, 3:02 AMTimothy Jones
06/23/2022, 3:03 AMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
João Luiz Vieira
06/23/2022, 3:11 AMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Timothy Jones
06/23/2022, 3:13 AMMatt (pactflow.io / pact-js / pact-go)
Timothy Jones
06/23/2022, 3:13 AMMatt (pactflow.io / pact-js / pact-go)
João Luiz Vieira
06/23/2022, 3:14 AMJoão Luiz Vieira
06/23/2022, 3:16 AMJoão Luiz Vieira
06/23/2022, 3:17 AMuglyog
uglyog
Timothy Jones
06/23/2022, 3:24 AMTimothy Jones
06/23/2022, 3:24 AMJoão Luiz Vieira
06/23/2022, 3:32 AMTimothy Jones
06/23/2022, 4:21 AM