diff --git a/message/v4/asynchronous_message_test.go b/message/v4/asynchronous_message_test.go index ce02b9053..e01114825 100644 --- a/message/v4/asynchronous_message_test.go +++ b/message/v4/asynchronous_message_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/assert" ) +// Sync - no plugin func TestAsyncTypeSystem(t *testing.T) { p, _ := NewAsynchronousPact(Config{ Consumer: "asyncconsumer", @@ -20,7 +21,6 @@ func TestAsyncTypeSystem(t *testing.T) { Foo string `json:"foo"` } - // Sync - no plugin err := p.AddAsynchronousMessage(). Given("some state"). Given("another state"). @@ -38,8 +38,11 @@ func TestAsyncTypeSystem(t *testing.T) { assert.NoError(t, err) - // Sync - with plugin, but no transport - // TODO: ExecuteTest has been disabled for now, because it's not very useful +} + +// Sync - with plugin, but no transport +// TODO: ExecuteTest has been disabled for now, because it's not very useful +func TestAsyncTypeSystem_CsvPlugin_Matcher(t *testing.T) { csvInteraction := `{ "request.path": "/reports/report002.csv", "response.status": "200", @@ -52,14 +55,14 @@ func TestAsyncTypeSystem(t *testing.T) { } }` - p, _ = NewAsynchronousPact(Config{ + p, _ := NewAsynchronousPact(Config{ Consumer: "asyncconsumer", Provider: "asyncprovider", PactDir: "/tmp/", }) // TODO: enable when there is a transport for async to test! - err = p.AddAsynchronousMessage(). + err := p.AddAsynchronousMessage(). Given("some state"). ExpectsToReceive("some csv content"). UsingPlugin(PluginConfig{ diff --git a/message/v4/synchronous_message_test.go b/message/v4/synchronous_message_test.go index 623060e87..3beb76b7e 100644 --- a/message/v4/synchronous_message_test.go +++ b/message/v4/synchronous_message_test.go @@ -4,43 +4,21 @@ import ( "errors" "fmt" "os" + "strings" "testing" "github.com/pact-foundation/pact-go/v2/log" "github.com/stretchr/testify/assert" ) -func TestSyncTypeSystem(t *testing.T) { +func TestSyncTypeSystem_NoPlugin(t *testing.T) { p, _ := NewSynchronousPact(Config{ Consumer: "consumer", Provider: "provider", PactDir: "/tmp/", }) - _ = log.SetLogLevel("INFO") - - dir, _ := os.Getwd() - path := fmt.Sprintf("%s/../../internal/native/pact_plugin.proto", dir) - - grpcInteraction := `{ - "pact:proto": "` + path + `", - "pact:proto-service": "PactPlugin/InitPlugin", - "pact:content-type": "application/protobuf", - "request": { - "implementation": "notEmpty('pact-go-driver')", - "version": "matching(semver, '0.0.0')" - }, - "response": { - "catalogue": [ - { - "type": "INTERACTION", - "key": "test" - } - ] - } - }` - // Sync - no plugin - _ = p.AddSynchronousMessage("some description"). + err := p.AddSynchronousMessage("some description"). Given("some state"). WithRequest(func(r *SynchronousMessageWithRequestBuilder) { r.WithJSONContent(map[string]string{"foo": "bar"}) @@ -64,8 +42,17 @@ func TestSyncTypeSystem(t *testing.T) { return nil }) + assert.NoError(t, err) +} + +// Sync - with plugin, but no transport +func TestSyncTypeSystem_CsvPlugin_Matcher(t *testing.T) { + p, _ := NewSynchronousPact(Config{ + Consumer: "consumer", + Provider: "provider", + PactDir: "/tmp/", + }) - // Sync - with plugin, but no transport csvInteraction := `{ "request.path": "/reports/report002.csv", "response.status": "200", @@ -78,16 +65,11 @@ func TestSyncTypeSystem(t *testing.T) { } }` - p, _ = NewSynchronousPact(Config{ - Consumer: "consumer", - Provider: "provider", - PactDir: "/tmp/", - }) - _ = p.AddSynchronousMessage("some description"). + err := p.AddSynchronousMessage("some description"). Given("some state"). UsingPlugin(PluginConfig{ Plugin: "csv", - Version: "0.0.1", + Version: "0.0.6", }). WithContents(csvInteraction, "text/csv"). ExecuteTest(t, func(m SynchronousMessage) error { @@ -95,11 +77,36 @@ func TestSyncTypeSystem(t *testing.T) { return nil }) - p, _ = NewSynchronousPact(Config{ + assert.NoError(t, err) +} +func TestSyncTypeSystem_ProtobufPlugin_Matcher_Transport(t *testing.T) { + _ = log.SetLogLevel("INFO") + p, _ := NewSynchronousPact(Config{ Consumer: "consumer", Provider: "provider", PactDir: "/tmp/", }) + dir, _ := os.Getwd() + path := fmt.Sprintf("%s/../../internal/native/pact_plugin.proto", strings.ReplaceAll(dir, "\\", "/")) + + grpcInteraction := `{ + "pact:proto": "` + path + `", + "pact:proto-service": "PactPlugin/InitPlugin", + "pact:content-type": "application/protobuf", + "request": { + "implementation": "notEmpty('pact-go-driver')", + "version": "matching(semver, '0.0.0')" + }, + "response": { + "catalogue": [ + { + "type": "INTERACTION", + "key": "test" + } + ] + } + }` + // Sync - with plugin + transport (pass) err := p.AddSynchronousMessage("some description"). Given("some state"). @@ -116,15 +123,49 @@ func TestSyncTypeSystem(t *testing.T) { }) assert.Error(t, err) + // assert.Equal(t, "Did not receive any requests for path 'PactPlugin/InitPlugin'", err) + // TODO:- Work out why we get the following error message + + // Error + // synchronous_message_test.go:130: + // Error Trace: /Users/saf/dev/pact-foundation/pact-go/message/v4/synchronous_message_test.go:130 + // Error: Not equal: + // expected: string("Did not receive any requests for path 'PactPlugin/InitPlugin'") + // actual : *errors.errorString(&errors.errorString{s:"pact validation failed: [{Request:{Method: Path:PactPlugin/InitPlugin Query: Headers:map[] Body:} Mismatches:[] Type:}]"}) + // Logs + // 2024-07-04T01:36:33.745740Z DEBUG ThreadId(01) pact_plugin_driver::plugin_manager: Got response: ShutdownMockServerResponse { ok: false, results: [MockServerResult { path: "PactPlugin/InitPlugin", error: "Did not receive any requests for path 'PactPlugin/InitPlugin'", mismatches: [] }] } +} - p, _ = NewSynchronousPact(Config{ +// Sync - with plugin + transport (fail) +func TestSyncTypeSystem_ProtobufPlugin_Matcher_Transport_Fail(t *testing.T) { + p, _ := NewSynchronousPact(Config{ Consumer: "consumer", Provider: "provider", PactDir: "/tmp/", }) + _ = log.SetLogLevel("INFO") + dir, _ := os.Getwd() + path := fmt.Sprintf("%s/../../internal/native/pact_plugin.proto", strings.ReplaceAll(dir, "\\", "/")) + + grpcInteraction := `{ + "pact:proto": "` + path + `", + "pact:proto-service": "PactPlugin/InitPlugin", + "pact:content-type": "application/protobuf", + "request": { + "implementation": "notEmpty('pact-go-driver')", + "version": "matching(semver, '0.0.0')" + }, + "response": { + "catalogue": [ + { + "type": "INTERACTION", + "key": "test" + } + ] + } + }` - // Sync - with plugin + transport (fail) - err = p.AddSynchronousMessage("some description"). + err := p.AddSynchronousMessage("some description"). Given("some state"). UsingPlugin(PluginConfig{ Plugin: "protobuf",