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

feat: Allow debug mock server in compatibility suites #621

Merged
merged 1 commit into from
Aug 29, 2024

Conversation

tienvx
Copy link
Contributor

@tienvx tienvx commented Aug 29, 2024

Currently running compatibility suites tests doesn't print out any mock server's log messages. So it's hard to debug failed test like this:

Then a 200 success response is returned
      Failed asserting that 500 is identical to 200.

And there is no way to customize this.

This PR pass the PACT_LOGLEVEL env to mock server. It allow me to run the behat command with custom (mock server) debug level:

env PACT_LOGLEVEL=debug vendor/bin/behat compatibility-suite/pact-compatibility-suite/features/V1/http_consumer.feature:204 --colors

Then it will print out useful log messages from mock server like this:

...
2024-08-29T05:41:00.882246Z DEBUG tokio-runtime-worker pact_matching: --> Mismatches: [HeaderMismatch { key: "Content-Type", expected: "text/plain", actual: "application/x-www-form-urlencoded", mismatch: "Mismatch with header 'Content-Type': Expected header 'Content-Type' to have value 'text/plain' but was 'application/x-www-form-urlencoded'" }, BodyTypeMismatch { expected: "text/plain", actual: "application/x-www-form-urlencoded", mismatch: "Expected a body of 'text/plain' but the actual content type was 'application/x-www-form-urlencoded'", expected_body: Some(b"a=1&b=2&c=3&d=4"), actual_body: Some(b"a=1&b=2&c=3&d=4") }]
2024-08-29T05:41:00.882281Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Request did not match: Request did not match - HTTP Request ( method: PUT, path: /form, query: None, headers: Some({"Content-Type": ["text/plain"]}), body: Present(15 bytes) )    0) Mismatch with header 'Content-Type': Expected header 'Content-Type' to have value 'text/plain' but was 'application/x-www-form-urlencoded'    1) Expected a body of 'text/plain' but the actual content type was 'application/x-www-form-urlencoded'
...

If PACT_LOGLEVEL is not set, it will not print anything, just like before.

@tienvx tienvx added the enhancement Indicates new feature requests label Aug 29, 2024
@tienvx tienvx requested a review from YOU54F August 29, 2024 05:58
@coveralls
Copy link

Pull Request Test Coverage Report for Build 10609536084

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 97.313%

Totals Coverage Status
Change from base Build 10370970040: 0.0%
Covered Lines: 2282
Relevant Lines: 2345

💛 - Coveralls

@tienvx tienvx merged commit 11502e9 into pact-foundation:master Aug 29, 2024
23 of 30 checks passed
@tienvx tienvx deleted the behat-debug-mock-server branch August 29, 2024 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Indicates new feature requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants