1- package v3
1+ package consumer
22
33import (
44 "encoding/json"
55 "fmt"
66 "log"
77 "strings"
88
9- "github.com/pact-foundation/pact-go/v3/internal/native/mockserver"
9+ "github.com/pact-foundation/pact-go/internal/native/mockserver"
10+ "github.com/pact-foundation/pact-go/matchers"
11+ "github.com/pact-foundation/pact-go/models"
12+ "github.com/pact-foundation/pact-go/utils"
1013)
1114
1215// Interaction is the main implementation of the Pact interface.
1316type Interaction struct {
1417 // Reference to the native rust handle
1518 interaction * mockserver.Interaction
16- specificationVersion SpecificationVersion
19+ specificationVersion models. SpecificationVersion
1720}
1821
1922type InteractionRequest struct {
@@ -39,7 +42,7 @@ func (i *Interaction) UponReceiving(description string) *Interaction {
3942// WithRequest specifies the details of the HTTP request that will be used to
4043// confirm that the Provider provides an API listening on the given interface.
4144// Mandatory.
42- func (i * Interaction ) WithRequest (method Method , path Matcher ) * InteractionRequest {
45+ func (i * Interaction ) WithRequest (method models. Method , path matchers. Matcher ) * InteractionRequest {
4346 i .interaction .WithRequest (string (method ), path )
4447
4548 return & InteractionRequest {
@@ -48,13 +51,13 @@ func (i *Interaction) WithRequest(method Method, path Matcher) *InteractionReque
4851 }
4952}
5053
51- func (i * InteractionRequest ) WithQuery (key string , values ... Matcher ) * InteractionRequest {
54+ func (i * InteractionRequest ) WithQuery (key string , values ... matchers. Matcher ) * InteractionRequest {
5255 i .interactionHandle .WithQuery (keyValuesToMapStringArrayInterface (key , values ... ))
5356
5457 return i
5558}
5659
57- func (i * InteractionRequest ) WithHeader (key string , values ... Matcher ) * InteractionRequest {
60+ func (i * InteractionRequest ) WithHeader (key string , values ... matchers. Matcher ) * InteractionRequest {
5861 i .interactionHandle .WithRequestHeaders (keyValuesToMapStringArrayInterface (key , values ... ))
5962
6063 return i
@@ -70,7 +73,7 @@ func (i *InteractionRequest) WithJSONBody(body interface{}) *InteractionRequest
7073 // Check if someone tried to add an object as a string representation
7174 // as per original allowed implementation, e.g.
7275 // { "foo": "bar", "baz": like("bat") }
73- if isJSONFormattedObject (string (s )) {
76+ if utils . IsJSONFormattedObject (string (s )) {
7477 log .Println ("[WARN] request body appears to be a JSON formatted object, " +
7578 "no matching will occur. Support for structured strings has been" +
7679 "deprecated as of 0.13.0. Please use the JSON() method instead" )
@@ -92,7 +95,7 @@ func (i *InteractionRequest) WithBody(contentType string, body []byte) *Interact
9295 // Check if someone tried to add an object as a string representation
9396 // as per original allowed implementation, e.g.
9497 // { "foo": "bar", "baz": like("bat") }
95- if isJSONFormattedObject (string (body )) {
98+ if utils . IsJSONFormattedObject (string (body )) {
9699 log .Println ("[WARN] request body appears to be a JSON formatted object, " +
97100 "no matching will occur. Support for structured strings has been" +
98101 "deprecated as of 0.13.0. Please use the JSON() method instead" )
@@ -104,7 +107,7 @@ func (i *InteractionRequest) WithBody(contentType string, body []byte) *Interact
104107}
105108
106109func (i * InteractionRequest ) WithBodyMatch (body interface {}) * InteractionRequest {
107- i .interactionHandle .WithJSONRequestBody (MatchV2 (body ))
110+ i .interactionHandle .WithJSONRequestBody (matchers . MatchV2 (body ))
108111
109112 return i
110113}
@@ -122,7 +125,7 @@ func (i *InteractionRequest) WillRespondWith(status int) *InteractionResponse {
122125 }
123126}
124127
125- func (i * InteractionResponse ) WithHeader (key string , values ... Matcher ) * InteractionResponse {
128+ func (i * InteractionResponse ) WithHeader (key string , values ... matchers. Matcher ) * InteractionResponse {
126129 i .interactionHandle .WithRequestHeaders (keyValuesToMapStringArrayInterface (key , values ... ))
127130
128131 return i
@@ -138,7 +141,7 @@ func (i *InteractionResponse) WithJSONBody(body interface{}) *InteractionRespons
138141 // Check if someone tried to add an object as a string representation
139142 // as per original allowed implementation, e.g.
140143 // { "foo": "bar", "baz": like("bat") }
141- if isJSONFormattedObject (string (s )) {
144+ if utils . IsJSONFormattedObject (string (s )) {
142145 log .Println ("[WARN] request body appears to be a JSON formatted object, " +
143146 "no matching will occur. Support for structured strings has been" +
144147 "deprecated as of 0.13.0. Please use the JSON() method instead" )
@@ -162,12 +165,12 @@ func (i *InteractionResponse) WithBody(contentType string, body []byte) *Interac
162165}
163166
164167func (i * InteractionResponse ) WithBodyMatch (body interface {}) * InteractionResponse {
165- i .interactionHandle .WithJSONRequestBody (MatchV2 (body ))
168+ i .interactionHandle .WithJSONRequestBody (matchers . MatchV2 (body ))
166169
167170 return i
168171}
169172
170- func validateMatchers (version SpecificationVersion , obj interface {}) error {
173+ func validateMatchers (version models. SpecificationVersion , obj interface {}) error {
171174 if obj == nil {
172175 return nil
173176 }
@@ -193,7 +196,7 @@ func validateMatchers(version SpecificationVersion, obj interface{}) error {
193196 return nil
194197}
195198
196- func hasMatcherGreaterThanSpec (version SpecificationVersion , obj map [string ]interface {}) []string {
199+ func hasMatcherGreaterThanSpec (version models. SpecificationVersion , obj map [string ]interface {}) []string {
197200 results := make ([]string , 0 )
198201
199202 for k , v := range obj {
@@ -235,7 +238,7 @@ func hasMatcherGreaterThanSpec(version SpecificationVersion, obj map[string]inte
235238// return i
236239// }
237240
238- func keyValuesToMapStringArrayInterface (key string , values ... Matcher ) map [string ][]interface {} {
241+ func keyValuesToMapStringArrayInterface (key string , values ... matchers. Matcher ) map [string ][]interface {} {
239242 q := make (map [string ][]interface {})
240243 for _ , v := range values {
241244 q [key ] = append (q [key ], v )
0 commit comments