From de7648033ab2c3089d2fecd8c17fc8dee9c4351c Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Thu, 25 Jul 2024 14:38:02 +0100 Subject: [PATCH] chore(avro): windows - skip avro plugin as it fails to start see https://github.com/pact-foundation/pact-plugins/issues/68 --- examples/avro/avro_consumer_test.go | 63 +++++++++++++++-------------- examples/avro/avro_provider_test.go | 28 +++++++------ 2 files changed, 48 insertions(+), 43 deletions(-) diff --git a/examples/avro/avro_consumer_test.go b/examples/avro/avro_consumer_test.go index 07111c749..15613893e 100644 --- a/examples/avro/avro_consumer_test.go +++ b/examples/avro/avro_consumer_test.go @@ -9,6 +9,7 @@ import ( "net/http" "net/url" "os" + "strings" "testing" "github.com/pact-foundation/pact-go/v2/consumer" @@ -21,17 +22,18 @@ import ( var dir, _ = os.Getwd() func TestAvroHTTP(t *testing.T) { - mockProvider, err := consumer.NewV4Pact(consumer.MockHTTPProviderConfig{ - Consumer: "AvroConsumer", - Provider: "AvroProvider", - PactDir: filepath.ToSlash(fmt.Sprintf("%s/../pacts", dir)), - }) - assert.NoError(t, err) + if os.Getenv("SKIP_PLUGIN_AVRO") != "1" { + mockProvider, err := consumer.NewV4Pact(consumer.MockHTTPProviderConfig{ + Consumer: "AvroConsumer", + Provider: "AvroProvider", + PactDir: filepath.ToSlash(fmt.Sprintf("%s/../pacts", dir)), + }) + assert.NoError(t, err) - dir, _ := os.Getwd() - path := fmt.Sprintf("%s/user.avsc", dir) + dir, _ := os.Getwd() + path := fmt.Sprintf("%s/user.avsc", strings.ReplaceAll(dir, "\\", "/")) - avroResponse := `{ + avroResponse := `{ "pact:avro": "` + path + `", "pact:record-name": "User", "pact:content-type": "avro/binary", @@ -39,27 +41,28 @@ func TestAvroHTTP(t *testing.T) { "username": "notEmpty('matt')" }` - // Set up our expected interactions. - err = mockProvider. - AddInteraction(). - UponReceiving("A request to do get some Avro stuff"). - UsingPlugin(consumer.PluginConfig{ - Plugin: "avro", - Version: "0.0.5", - }). - WithRequest("GET", "/avro"). - WillRespondWith(200, func(res *consumer.V4InteractionWithPluginResponseBuilder) { - res.PluginContents("avro/binary", avroResponse) - }). - ExecuteTest(t, func(msc consumer.MockServerConfig) error { - resp, err := callServiceHTTP(msc) - - assert.Equal(t, int64(1), resp.ID) - assert.Equal(t, "matt", resp.Username) // ??????! - - return err - }) - assert.NoError(t, err) + // Set up our expected interactions. + err = mockProvider. + AddInteraction(). + UponReceiving("A request to do get some Avro stuff"). + UsingPlugin(consumer.PluginConfig{ + Plugin: "avro", + Version: "0.0.5", + }). + WithRequest("GET", "/avro"). + WillRespondWith(200, func(res *consumer.V4InteractionWithPluginResponseBuilder) { + res.PluginContents("avro/binary", avroResponse) + }). + ExecuteTest(t, func(msc consumer.MockServerConfig) error { + resp, err := callServiceHTTP(msc) + + assert.Equal(t, int64(1), resp.ID) + assert.Equal(t, "matt", resp.Username) // ??????! + + return err + }) + assert.NoError(t, err) + } } func callServiceHTTP(msc consumer.MockServerConfig) (*User, error) { diff --git a/examples/avro/avro_provider_test.go b/examples/avro/avro_provider_test.go index d8cbaf331..38779439c 100644 --- a/examples/avro/avro_provider_test.go +++ b/examples/avro/avro_provider_test.go @@ -21,23 +21,25 @@ var dir, _ = os.Getwd() var pactDir = fmt.Sprintf("%s/../pacts", dir) func TestAvroHTTPProvider(t *testing.T) { - httpPort, _ := utils.GetFreePort() + if os.Getenv("SKIP_PLUGIN_AVRO") != "1" { + httpPort, _ := utils.GetFreePort() - // Start provider API in the background - go startHTTPProvider(httpPort) + // Start provider API in the background + go startHTTPProvider(httpPort) - verifier := provider.NewVerifier() + verifier := provider.NewVerifier() - // Verify the Provider with local Pact Files - err := verifier.VerifyProvider(t, provider.VerifyRequest{ - ProviderBaseURL: fmt.Sprintf("http://127.0.0.1:%d", httpPort), - Provider: "AvroProvider", - PactFiles: []string{ - filepath.ToSlash(fmt.Sprintf("%s/AvroConsumer-AvroProvider.json", pactDir)), - }, - }) + // Verify the Provider with local Pact Files + err := verifier.VerifyProvider(t, provider.VerifyRequest{ + ProviderBaseURL: fmt.Sprintf("http://127.0.0.1:%d", httpPort), + Provider: "AvroProvider", + PactFiles: []string{ + filepath.ToSlash(fmt.Sprintf("%s/AvroConsumer-AvroProvider.json", pactDir)), + }, + }) - assert.NoError(t, err) + assert.NoError(t, err) + } } func startHTTPProvider(port int) {