This gist describes how to run the proof of concept for protobufs-over-HTTP for the Pact framework.
It's worth noting that this work isn't yet in a production-ready state, and at this stage is a first illustrative step of what can be done in this space.
The ideas implemented here, are described in this presentation.
The pact-serialization-proxy component referred to in the presentation has a repo which can be found here.
-
Try to get a protobuf object as a Pact consumer https://github.com/mcon/pact-net/blob/protobuf-serialization/Samples/EventApi/Consumer/EventsApiClient.cs#L243
-
Orchestration changed to use pact-serialization-proxy in addition to the Ruby core as per the archetecture diagram https://github.com/mcon/pact-serialization-proxy#design: https://github.com/mcon/pact-net/blob/protobuf-serialization/Samples/EventApi/Consumer.Tests/ConsumerEventApiPact.cs#L30
-
Test that consumer can get protobuf object: https://github.com/mcon/pact-net/blob/protobuf-serialization/Samples/EventApi/Consumer.Tests/EventsApiConsumerTests.cs#L353
-
Create a server which returns a protobuf-serialized response https://github.com/mcon/pact-net/blob/protobuf-serialization/Samples/EventApi/Provider.Api.Web/Controllers/PersonController.cs
-
No change required to the verification code, as the PoC mandates the use of the pact-serialization-proxy
https://github.com/mcon/pact-serialization-proxy/releases
- Install golang https://golang.org/doc/install - I used 1.12.5 linux/amd64 -- Go to your GOPATH
cd `go env | grep GOPATH | cut -d = -f 2 | tr -d '"'`
go get github.com/mcon/pact-serialization-proxy/cmd/proxy-server
cd src/github.com/mcon/pact-serialization-proxy
make build
PACT_PROXY_SERVER=realpath proxy-server
- Note down the fully qualified path of the proxy server binary
- Download .NET core: https://dotnet.microsoft.com/download - I used version 2.1.802
mkdir ~/proto-example
cd !$
git clone https://github.com/mcon/pact-net.git --branch protobuf-serialization
cd pact-net
- Swap out hacked hard-coded location of pact-serialization-proxy with your version
find . -name "*.cs" | xargs -i sed "s|/home/matt/go/src/github.com/mcon/pact-serialization-proxy/proxy-server|$PACT_PROXY_SERVER|g" -i {}
- Generate consumer contract
dotnet test Samples/EventApi/Consumer.Tests/
- Note that the generated contract has an entry with an "encoding" field:
cat Samples/EventApi/Consumer.Tests/pacts/event_api_consumer-event_api.proto.json
- Verify the pact contract
dotnet test Samples/EventApi/Provider.Api.Web.Tests/
Note: sometimes the pact-serialization-proxy isn't shut down correctly (the .NET code I've hacked together isn't terribly robust), pkill proxy-server
should kill it.