pact-mock_service icon indicating copy to clipboard operation
pact-mock_service copied to clipboard

Allow different content types

Open yadavsaroj opened this issue 9 years ago • 6 comments

Hey there!

I am thinking of using pact-mock_service with a microservice that accepts Avro JSON and binary data. Looks like currently pact-mock_service only support JSON data. I am curious about your thoughts on extending it to support different content types?

Best! Saroj

yadavsaroj avatar Nov 24 '15 00:11 yadavsaroj

You will need to implement a differ (this generates a diff) and a diff formatter (this displays the diff in a meaningful way) and set these based on the content type. Copy the code example here: https://github.com/bethesque/pact-xml

bethesque avatar Nov 24 '15 02:11 bethesque

Thanks! I will take a look.

yadavsaroj avatar Nov 24 '15 18:11 yadavsaroj

Can confirm this issue because of this line of code: https://github.com/bethesque/pact-mock_service/blob/master/lib/pact/mock_service/request_handlers/interaction_replay.rb#L16

It will fail if it's not JSON. We were trying to use it to check a binary upload, but we're not matching on the body, only the headers of the requests which I feel should still work.

mboudreau avatar Jun 09 '16 05:06 mboudreau

It works with text/plain content type, so that line should not be an issue. This question has been asked so many times, that I've finally written it up in the wiki and added it to the FAQ.

https://github.com/realestate-com-au/pact/wiki/How-to-extend-Pact-for-different-content-types

Michel, if there's somewhere else that this content belongs now, let me know.

On Thu, Jun 9, 2016 at 3:27 PM, Michel Boudreau [email protected] wrote:

Can confirm this issue because of this line of code: https://github.com/bethesque/pact-mock_service/blob/master/lib/pact/mock_service/request_handlers/interaction_replay.rb#L16

It will fail if it's not JSON. We were trying to use it to check a binary upload, but we're not matching on the body, only the headers of the requests which I feel should still work.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bethesque/pact-mock_service/issues/32#issuecomment-224803328, or mute the thread https://github.com/notifications/unsubscribe/AAbPFJ9307IqdXuHia9IyA02JNDIXGy1ks5qJ6RSgaJpZM4Gn_sd .

bethesque avatar Jun 09 '16 06:06 bethesque

The problem I see is that people using pact aren't particularly using Ruby. In this case, it's all node and they're so abstracted to the Ruby binary that there's no way to change the configuration of it or make it scalable within the business.

I'm not asking to create diffs for all the different content types, in this case, the only contract is through the http headers, but it still fails if the body isn't utf8, even though no matching is to be done. We should be able to at least not make it crash.

On Thu, Jun 9, 2016, 4:12 PM Beth Skurrie [email protected] wrote:

It works with text/plain content type, so that line should not be an issue. This question has been asked so many times, that I've finally written it up in the wiki and added it to the FAQ.

https://github.com/realestate-com-au/pact/wiki/How-to-extend-Pact-for-different-content-types

Michel, if there's somewhere else that this content belongs now, let me know.

On Thu, Jun 9, 2016 at 3:27 PM, Michel Boudreau [email protected] wrote:

Can confirm this issue because of this line of code:

https://github.com/bethesque/pact-mock_service/blob/master/lib/pact/mock_service/request_handlers/interaction_replay.rb#L16

It will fail if it's not JSON. We were trying to use it to check a binary upload, but we're not matching on the body, only the headers of the requests which I feel should still work.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub < https://github.com/bethesque/pact-mock_service/issues/32#issuecomment-224803328 , or mute the thread < https://github.com/notifications/unsubscribe/AAbPFJ9307IqdXuHia9IyA02JNDIXGy1ks5qJ6RSgaJpZM4Gn_sd

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bethesque/pact-mock_service/issues/32#issuecomment-224808678, or mute the thread https://github.com/notifications/unsubscribe/AAjA5NdAvOIaLFhLRRrvT2N9Ng_mHbVlks5qJ67ZgaJpZM4Gn_sd .

mboudreau avatar Jun 09 '16 06:06 mboudreau

Hm. There was a reason for the UTF-8, but I can't remember it now. If someone wants to work on this, it shouldn't be too hard.

Sigh... baby number 1 calls...

On Thu, Jun 9, 2016 at 4:17 PM, Michel Boudreau [email protected] wrote:

The problem I see is that people using pact aren't particularly using Ruby. In this case, it's all node and they're so abstracted to the Ruby binary that there's no way to change the configuration of it or make it scalable within the business.

I'm not asking to create diffs for all the different content types, in this case, the only contract is through the http headers, but it still fails if the body isn't utf8, even though no matching is to be done. We should be able to at least not make it crash.

On Thu, Jun 9, 2016, 4:12 PM Beth Skurrie [email protected] wrote:

It works with text/plain content type, so that line should not be an issue. This question has been asked so many times, that I've finally written it up in the wiki and added it to the FAQ.

https://github.com/realestate-com-au/pact/wiki/How-to-extend-Pact-for-different-content-types

Michel, if there's somewhere else that this content belongs now, let me know.

On Thu, Jun 9, 2016 at 3:27 PM, Michel Boudreau < [email protected]> wrote:

Can confirm this issue because of this line of code:

https://github.com/bethesque/pact-mock_service/blob/master/lib/pact/mock_service/request_handlers/interaction_replay.rb#L16

It will fail if it's not JSON. We were trying to use it to check a binary upload, but we're not matching on the body, only the headers of the requests which I feel should still work.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub <

https://github.com/bethesque/pact-mock_service/issues/32#issuecomment-224803328

, or mute the thread <

https://github.com/notifications/unsubscribe/AAbPFJ9307IqdXuHia9IyA02JNDIXGy1ks5qJ6RSgaJpZM4Gn_sd

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub < https://github.com/bethesque/pact-mock_service/issues/32#issuecomment-224808678 , or mute the thread < https://github.com/notifications/unsubscribe/AAjA5NdAvOIaLFhLRRrvT2N9Ng_mHbVlks5qJ67ZgaJpZM4Gn_sd

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bethesque/pact-mock_service/issues/32#issuecomment-224809365, or mute the thread https://github.com/notifications/unsubscribe/AAbPFEc6NUpt3cFg5R1YKCopI7ufIz3Kks5qJ7AGgaJpZM4Gn_sd .

bethesque avatar Jun 09 '16 06:06 bethesque