Skip to content

Commit

Permalink
fix: satisfy checker interface in native lib
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed May 23, 2021
1 parent 60ed9b0 commit 3797399
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 76 deletions.
3 changes: 0 additions & 3 deletions v3/internal/native/mockserver/message_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions v3/internal/native/mockserver/mock_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
144 changes: 73 additions & 71 deletions v3/internal/native/mockserver/mock_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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+"
}
}
}]
}`
7 changes: 6 additions & 1 deletion v3/internal/native/verifier/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ 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)

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"))
Expand Down
5 changes: 4 additions & 1 deletion v3/internal/native/verifier/verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/stretchr/testify/assert"
)

func init() {
Init()
}

func TestVerifier_Version(t *testing.T) {
fmt.Println("version: ", Version())
}
Expand All @@ -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",
Expand Down

0 comments on commit 3797399

Please sign in to comment.