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
Incorrect matching of string #278
Comments
Thanks. This probably belongs in pact-js, not here. Also, please attach your pact file and any relevant logs. It looks like the matcher is not being serialised into the pact file, as it seems to be matching verbatim. |
Moved to pact js |
Pact file attached log file below |
@parasvora there appear to be multiple things wrong here. Firstly, your provider seems to be returning a bunch of base64 encoded things, but your test is expecting this much smaller object:
I think you perhaps have the request/response backwards? Are you indeed expecting to get back a base64 encoded object when you are sending the base64 object in the first place? Secondly, there are no matchers in the pact file, so any response is going to be matched exactly as you specified it - which is probably not what you want. Thirdly, the state also seems a bit strange: So for us to be able to help you, we're going to need to see the actual test code that you've written. |
The content node contains a Base64 encoded string. The snippet pasted above is exactly what I see in the pack broker upon using the below code,
My intention here is to check if there is a string that the node content contains in my response. I wont be bothering what is the content of the string. Please let me know incase further information is needed. |
From what I can gather, you are using string equality matchers, rather than
string type matchers, hence why when you receive a base64 payload it's not
matching the string literal "content".
See
https://github.com/DiUS/pact-jvm/blob/master/pact-jvm-consumer-junit/README.md#dsl-matching-methods
…On Mon, Mar 11, 2019, 4:21 AM Paras Vora ***@***.***> wrote:
@mefellows <https://github.com/mefellows>
"body": {
"content": "string",
"contentType": "application/pdf"
}
The *content* node contains a Base64 encoded string.
The snippet pasted above is exactly what I see in the pack broker upon
using the below code,
private DslPart getRequestBody() {
JSONObject jSonRequest = null;
try {
InputStream is = getClass()
.getResourceAsStream(PATH_TO_TEST_DATA + FILE_HTML_REQUEST_BASE64);
checkNotNull(is, String.format("File %s not found", FILE_HTML_REQUEST_BASE64));
jSonRequest = GetFileContent.getFileContent(is);
} catch (Exception e){
e.printStackTrace();
}
return new PactDslJsonBody()
.stringValue("header", jSonRequest.getString("header"))
.stringValue("footer", jSonRequest.getString("footer"))
.stringValue("body", jSonRequest.getString("body"))
.object("page")
.stringValue("format", "A4")
.stringValue("height", "11in")
.stringValue("width", "8.5in")
.closeObject();
}
private DslPart getResponseBody() {
return new PactDslJsonBody()
.stringType("content")
.stringValue("contentType","application/pdf")
}
public PactDslResponse buildPact(PactDslWithProvider builder) {
final Map<String, String> header = ImmutableMap.<String, String>builder()
.put("Content-Type", "application/json; charset=utf-8")
.build();
return builder
.given("Return Base64 ecoded pdf stream")
.uponReceiving("Request to fetch the Base64 ecoded pdf stream")
.headers(header)
.body(this.getRequestBody().asBody())
.path(END_POINT)
.method("POST")
.willRespondWith()
.headers(header)
.body(this.getResponseBody().asBody())
.status(200);
}
My intention here is to check if there is a string that the node *content*
contains in my response. I wont be bothering what is the content of the
string.
Please let me know incase further information is needed.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#278 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADSjAPrnhmVvtZS9yBOfqqRV-AQR9Eiks5vVT78gaJpZM4bkxd5>
.
|
@mefellows String literals here is the value of the node content in the below json,
I am using the For further clarity, I am attaching the actual request & response. |
Thanks @parasvora. The problem is, that in your consumer test you're matching on string literals, and not the general string type. What this means is that when the provider responds, the values must match exactly as they are in the pact file. Which of course they aren't, because "content" does not match the 50k+ character base64 encoded string that it's returning. At the very least, you need to change your matchers from Unless I'm mistaking something greatly, at which point we'd love to have a reproducible project that we can download and run to validate this issue. |
@mefellows
|
Apologies, you are right there. @uglyog it seems no matchers are being generated for the |
@mefellows |
@parasvora don't call Instead: return builder
.given("Return Base64 ecoded pdf stream")
.uponReceiving("Request to fetch the Base64 ecoded pdf stream")
.headers(header)
.body(this.getRequestBody()) // <--
.path(END_POINT)
.method("POST")
.willRespondWith()
.headers(header)
.body(this.getResponseBody()) // <--
.status(200); |
Closing due to inactivity. I believe there is a working solution. |
Software versions
node --version
11.6.0Expected behaviour
Expected api response set from pact-jvm
Below is updated in the pact-broker
Below is the provider script in pact-node:
The matching on the response for node content in the expected response should pass any string.
Actual behaviour
The word string is compared with the actual response.
Steps to reproduce
Provide a repository, gist or reproducible code snippet so that we can test the problem.
Consider forking the project and modifying the E2E test
Relevant log files
Please ensure you set logging to
DEBUG
and attach any relevant log files here (or link from a gist).The text was updated successfully, but these errors were encountered: