Software versions
- OS: e.g. Mac OSX 11.6
- Consumer Pact library: Pact go v1.6.4
- Provider Pact library: Pact go v1.6.4
- Golang Version: go1.14.2 darwin/amd64
- Golang environment:
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/admin/Library/Caches/go-build"
GOENV="/Users/admin/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/admin/dev/go"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/local/go"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/admin/dev/my-project/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/q8/g6cp7z_93q18l9_6gbbz798m0000gp/T/go-build038959026=/tmp/go-build -gno-record-gcc-switches -fno-common"
Expected behaviour
When generating a Pact from a Golang Struct that contains a UUID field, I expect the resulting Pact to contain a String version of the UUID.
Actual behaviour
The resulting Pact contains an array of bytes, which is the UUID fields underlying representation.
Steps to reproduce
The following code is an example on how to reproduce, and the resulting Pact file is below (note the body - ID field)
import (
"fmt"
"github.com/google/uuid"
"github.com/pact-foundation/pact-go/dsl"
"log"
"net/http"
"testing"
)
type Foo struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
}
func TestGet(t *testing.T) {
// Create Pact connecting to local Daemon
pact := &dsl.Pact{
Consumer: "my-consumer",
Provider: "my-provider",
Host: "localhost",
}
defer pact.Teardown()
// Pass in test case. This is the component that makes the external HTTP call
var test = func() (err error) {
u := fmt.Sprintf("http://localhost:%d/foobar", pact.Server.Port)
req, err := http.NewRequest("GET", u, nil)
if err != nil {
return
}
// NOTE: by default, request bodies are expected to be sent with a Content-Type
// of application/json. If you don't explicitly set the content-type, you
// will get a mismatch during Verification.
req.Header.Set("Content-Type", "application/json")
_, err = http.DefaultClient.Do(req)
return
}
// Set up our expected interactions.
pact.
AddInteraction().
Given("Data exists").
UponReceiving("A request to get").
WithRequest(dsl.Request{
Method: "get",
Path: dsl.String("/foobar"),
Headers: dsl.MapMatcher{"Content-Type": dsl.String("application/json")},
}).
WillRespondWith(dsl.Response{
Status: 200,
Headers: dsl.MapMatcher{"Content-Type": dsl.String("application/json")},
Body: dsl.Match(&Foo{}),
})
// Run the test, verify it did what we expected and capture the contract
if err := pact.Verify(test); err != nil {
log.Fatalf("Error on Verify: %v", err)
}
}
{
"consumer": {
"name": "my-consumer"
},
"provider": {
"name": "my-provider"
},
"interactions": [
{
"description": "A request to get all ",
"providerState": "Data exists",
"request": {
"method": "get",
"path": "/foobar",
"headers": {
"Content-Type": "application/json"
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": {
"description": "string",
"id": [
1
],
"name": "string"
},
"matchingRules": {
"$.body.description": {
"match": "type"
},
"$.body.id": {
"min": 1
},
"$.body.id[*].*": {
"match": "type"
},
"$.body.id[*]": {
"match": "type"
},
"$.body.name": {
"match": "type"
}
}
}
}
],
"metadata": {
"pactSpecification": {
"version": "2.0.0"
}
}
}
Software versions
Expected behaviour
When generating a Pact from a Golang Struct that contains a UUID field, I expect the resulting Pact to contain a String version of the UUID.
Actual behaviour
The resulting Pact contains an array of bytes, which is the UUID fields underlying representation.
Steps to reproduce
The following code is an example on how to reproduce, and the resulting Pact file is below (note the body - ID field)