From 3797399ac169569b9bed78797284c4a8aea0467b Mon Sep 17 00:00:00 2001 From: Matt Fellows Date: Sun, 23 May 2021 23:17:43 +1000 Subject: [PATCH] fix: satisfy checker interface in native lib --- .../native/mockserver/message_server_test.go | 3 - v3/internal/native/mockserver/mock_server.go | 5 + .../native/mockserver/mock_server_test.go | 144 +++++++++--------- v3/internal/native/verifier/verifier.go | 7 +- v3/internal/native/verifier/verifier_test.go | 5 +- 5 files changed, 88 insertions(+), 76 deletions(-) diff --git a/v3/internal/native/mockserver/message_server_test.go b/v3/internal/native/mockserver/message_server_test.go index 80f244df5..66853650a 100644 --- a/v3/internal/native/mockserver/message_server_test.go +++ b/v3/internal/native/mockserver/message_server_test.go @@ -13,7 +13,6 @@ import ( ) func TestHandleBasedMessageTestsWithString(t *testing.T) { - Init() tmpPactFolder, err := ioutil.TempDir("", "pact-go") assert.NoError(t, err) s := NewMessageServer("test-message-consumer", "test-message-provider") @@ -46,7 +45,6 @@ func TestHandleBasedMessageTestsWithString(t *testing.T) { } func TestHandleBasedMessageTestsWithJSON(t *testing.T) { - Init() tmpPactFolder, err := ioutil.TempDir("", "pact-go") assert.NoError(t, err) s := NewMessageServer("test-message-consumer", "test-message-provider") @@ -80,7 +78,6 @@ func TestHandleBasedMessageTestsWithJSON(t *testing.T) { } func TestHandleBasedMessageTestsWithBinary(t *testing.T) { - Init() tmpPactFolder, err := ioutil.TempDir("", "pact-go") assert.NoError(t, err) diff --git a/v3/internal/native/mockserver/mock_server.go b/v3/internal/native/mockserver/mock_server.go index 726979552..04ab18d6f 100644 --- a/v3/internal/native/mockserver/mock_server.go +++ b/v3/internal/native/mockserver/mock_server.go @@ -225,6 +225,11 @@ func NewHTTPMockServer(consumer string, provider string) *MockServer { return &MockServer{pact: &Pact{handle: C.new_pact(cConsumer, cProvider)}} } +// Version returns the current semver FFI interface version +func (m *MockServer) Version() string { + return Version() +} + func (m *MockServer) WithSpecificationVersion(version specificationVersion) { C.with_specification(m.pact.handle, C.int(version)) } diff --git a/v3/internal/native/mockserver/mock_server_test.go b/v3/internal/native/mockserver/mock_server_test.go index 4fb231c47..3feba3758 100644 --- a/v3/internal/native/mockserver/mock_server_test.go +++ b/v3/internal/native/mockserver/mock_server_test.go @@ -9,79 +9,12 @@ import ( "github.com/stretchr/testify/assert" ) -var pactSimple = `{ - "consumer": { - "name": "consumer" - }, - "provider": { - "name": "provider" - }, - "interactions": [ - { - "description": "Some name for the test", - "request": { - "method": "GET", - "path": "/foobar" - }, - "response": { - "status": 200 - }, - "description": "Some name for the test", - "provider_state": "Some state" - }] -}` - -var pactComplex = `{ - "consumer": { - "name": "consumer" - }, - "provider": { - "name": "provider" - }, - "interactions": [ - { - "request": { - "method": "GET", - "path": "/foobar", - "body": { - "pass": 1234, - "user": { - "address": "some address", - "name": "someusername", - "phone": 12345678, - "plaintext": "plaintext" - } - } - }, - "response": { - "status": 200 - }, - "description": "Some name for the test", - "provider_state": "Some state", - "matchingRules": { - "$.body.pass": { - "match": "regex", - "regex": "\\d+" - }, - "$.body.user.address": { - "match": "regex", - "regex": "\\s+" - }, - "$.body.user.name": { - "match": "regex", - "regex": "\\s+" - }, - "$.body.user.phone": { - "match": "regex", - "regex": "\\d+" - } - } - }] -}` +func init() { + Init() +} func TestMockServer_CreateAndCleanupMockServer(t *testing.T) { m := MockServer{} - Init() port, _ := m.CreateMockServer(pactComplex, "0.0.0.0:0", false) defer m.CleanupMockServer(port) @@ -190,7 +123,6 @@ func TestVersion(t *testing.T) { } func TestHandleBasedHTTPTests(t *testing.T) { - Init() tmpPactFolder, err := ioutil.TempDir("", "pact-go") assert.NoError(t, err) @@ -236,3 +168,73 @@ func TestHandleBasedHTTPTests(t *testing.T) { fmt.Println(r) } + +var pactSimple = `{ + "consumer": { + "name": "consumer" + }, + "provider": { + "name": "provider" + }, + "interactions": [ + { + "description": "Some name for the test", + "request": { + "method": "GET", + "path": "/foobar" + }, + "response": { + "status": 200 + }, + "description": "Some name for the test", + "provider_state": "Some state" + }] +}` + +var pactComplex = `{ + "consumer": { + "name": "consumer" + }, + "provider": { + "name": "provider" + }, + "interactions": [ + { + "request": { + "method": "GET", + "path": "/foobar", + "body": { + "pass": 1234, + "user": { + "address": "some address", + "name": "someusername", + "phone": 12345678, + "plaintext": "plaintext" + } + } + }, + "response": { + "status": 200 + }, + "description": "Some name for the test", + "provider_state": "Some state", + "matchingRules": { + "$.body.pass": { + "match": "regex", + "regex": "\\d+" + }, + "$.body.user.address": { + "match": "regex", + "regex": "\\s+" + }, + "$.body.user.name": { + "match": "regex", + "regex": "\\s+" + }, + "$.body.user.phone": { + "match": "regex", + "regex": "\\d+" + } + } + }] +}` diff --git a/v3/internal/native/verifier/verifier.go b/v3/internal/native/verifier/verifier.go index 6014f0f60..56a761ac4 100644 --- a/v3/internal/native/verifier/verifier.go +++ b/v3/internal/native/verifier/verifier.go @@ -30,7 +30,7 @@ func Version() string { return C.GoString(version) } -func (v *Verifier) Init() { +func Init() { log.Println("[DEBUG] initialising rust verifier interface") logLevel := C.CString("LOG_LEVEL") defer freeString(logLevel) @@ -38,6 +38,11 @@ func (v *Verifier) Init() { C.init(logLevel) } +// Version returns the current semver FFI interface version +func (v *Verifier) Version() string { + return Version() +} + func (v *Verifier) Verify(args []string) error { log.Println("[DEBUG] executing verifier FFI with args", args) cargs := C.CString(strings.Join(args, "\n")) diff --git a/v3/internal/native/verifier/verifier_test.go b/v3/internal/native/verifier/verifier_test.go index ee2385950..68639dd5d 100644 --- a/v3/internal/native/verifier/verifier_test.go +++ b/v3/internal/native/verifier/verifier_test.go @@ -7,6 +7,10 @@ import ( "github.com/stretchr/testify/assert" ) +func init() { + Init() +} + func TestVerifier_Version(t *testing.T) { fmt.Println("version: ", Version()) } @@ -15,7 +19,6 @@ func TestVerifier_Verify(t *testing.T) { t.Run("invalid args returns an error", func(t *testing.T) { v := Verifier{} - v.Init() args := []string{ "--file", "/non/existent/path.json",