Skip to content

Instantly share code, notes, and snippets.

@mcon
Last active January 25, 2020 21:24
Show Gist options
  • Save mcon/2e3ae3eff0b9712d02e06ac1275b7f65 to your computer and use it in GitHub Desktop.
Save mcon/2e3ae3eff0b9712d02e06ac1275b7f65 to your computer and use it in GitHub Desktop.
Running the Pact protobufs-over-HTTP proof of concept

Introduction

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.

Example Pact-user code

Instructions

Get the pact-serialization proxy

Option 1: download the binary from GitHub (currently Linux only)

https://github.com/mcon/pact-serialization-proxy/releases

Option 2: build from source

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

Get the .NET pact branch with protobuf proof of concept

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment