Denis Peganov
03/22/2023, 2:21 PM[ERROR] API handler start failed: accept tcp [::]:42053
But basically I just need to validate the Handler's "handle" function and can do it in my unit tests by calling that func with mocked Handler's dependencies. I want to do the same with my contract tests.
Is it possible to validate the contract wihout the need to run local Handler or the running Handler is required?Denis Peganov
03/22/2023, 8:05 PMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Denis Peganov
03/23/2023, 2:42 PMden@WIN-S95P35K3NPM:/.../pact-go/examples$ go test -run TestMessagePact
...
../consumer/http.go:82:31: undefined: native.MockServer
../consumer/http.go:114:24: undefined: native.NewHTTPPact
../consumer/http.go:117:48: undefined: native.SPECIFICATION_VERSION_V2
../consumer/http.go:119:48: undefined: native.SPECIFICATION_VERSION_V3
../consumer/http.go:121:48: undefined: native.SPECIFICATION_VERSION_V4
../consumer/http.go:123:9: undefined: native.Init
../consumer/http.go:316:16: undefined: native.GetTLSConfig
../consumer/interaction.go:16:35: undefined: mockserver.Interaction
../consumer/http_v4.go:461:65: undefined: native.INTERACTION_PART_REQUEST
../consumer/http_v4.go:542:65: undefined: native.INTERACTION_PART_RESPONSE
../consumer/http_v4.go:542:65: too many errors
FAIL <http://github.com/pact-foundation/pact-go/v2/examples|github.com/pact-foundation/pact-go/v2/examples> [build failed]
And your example seems to be helpful, could you help me run this consumer_v3_test please?Denis Peganov
03/23/2023, 2:56 PMden@WIN-S95P35K3NPM:/.../sampleHandler/handler$ go test -run Test_verifyContract
2023/03/23 15:51:47 [INFO] checking pact-provider-verifier within range >= 1.36.1, < 2.0.0
2023/03/23 15:51:47 [INFO] checking pact-broker within range >= 1.22.3
2023/03/23 15:51:48 [INFO] checking pact-mock-service within range >= 3.5.0, < 4.0.0
2023/03/23 15:51:48 [WARN] state handler not found for state: given a SQS message
2023/03/23 15:51:48 [ERROR] *message handler not found for message description: expected to receive no error*
2023/03/23 15:51:48 [ERROR] *API handler start failed: accept tcp [::]:41565: use of closed network connection*
--- FAIL: Test_verifyContract (0.86s)
--- FAIL: Test_verifyContract/has_matching_content (0.00s)
pact.go:638: Verifying a pact between Sample Consumer and Sample Handler Given given a SQS message expected to receive no error has matching content
pact.go:644: Verifying a pact between Sample Consumer and Sample Handler Given given a SQS message expected to receive no error has matching content
An error was raised while verifying the message. The response body is:
FAIL
exit status 1
FAIL sampleHandler/handler 0.867s
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
diff --git a/handler/handler_contract_test.go b/handler/handler_contract_test.go
index 11d6b8b..ed1b4b1 100644
--- a/handler/handler_contract_test.go
+++ b/handler/handler_contract_test.go
@@ -3,8 +3,9 @@ package handler
import (
"path/filepath"
- "<http://github.com/pact-foundation/pact-go/dsl|github.com/pact-foundation/pact-go/dsl>"
"testing"
+
+ "<http://github.com/pact-foundation/pact-go/dsl|github.com/pact-foundation/pact-go/dsl>"
)
var data *SQSEvent
@@ -14,7 +15,7 @@ func Test_verifyContract(t *testing.T) {
// Map test descriptions to message producer (handlers)
functionMappings := dsl.MessageHandlers{
- "received data": func(m dsl.Message) (interface{}, error) {
+ "expected to receive no error": func(m dsl.Message) (interface{}, error) {
if data != nil {
return data, nil
} else {
@@ -26,7 +27,7 @@ func Test_verifyContract(t *testing.T) {
}
stateMappings := dsl.StateHandlers{
- "data exists": func(s dsl.State) error {
+ "given a SQS message": func(s dsl.State) error {
data = &SQSEvent{
SqsData: "12341234",
}
Matt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
Denis Peganov
03/27/2023, 1:59 PMMatt (pactflow.io / pact-js / pact-go)