pact-foundation / pact-mock_service

Provides a mock service for use with Pact
https://pact.io
MIT License
74 stars 69 forks source link

Allow different content types #32

Closed yadavsaroj closed 2 months ago

yadavsaroj commented 8 years ago

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

bethesque commented 8 years ago

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

yadavsaroj commented 8 years ago

Thanks! I will take a look.

mboudreau commented 8 years ago

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.

bethesque commented 8 years ago

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 notifications@github.com 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 .

mboudreau commented 8 years ago

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 notifications@github.com 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 notifications@github.com 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 .

bethesque commented 8 years ago

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 notifications@github.com 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 notifications@github.com 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 < notifications@github.com> 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 .

YOU54F commented 2 months ago

The recommend way now to support alternative content types is building your own pact plugin

https://docs.pact.io/plugins/quick_start

This is possible with the current rust mock server library/cli built in rust

https://github.com/pact-foundation/pact-core-mock-server

pact avro plugin is here

https://github.com/austek/pact-avro-plugin

examples of interop in ruby with the pact ffi library to use plugins are shown here, which will at some point be integrated with pact-ruby

https://github.com/YOU54F/pact-ruby-ffi