From a19fd06580277f3efd4f27bbfe28e88d13d715f6 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Fri, 30 Aug 2024 19:43:04 +0100 Subject: [PATCH 1/4] test: renable avro windows --- .github/workflows/test.yml | 4 -- Makefile | 12 +++--- examples/avro/avro_consumer_test.go | 63 ++++++++++++++--------------- examples/avro/avro_provider_test.go | 29 +++++++------ 4 files changed, 50 insertions(+), 58 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1c9e1bd19..928ece2ac 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -48,10 +48,6 @@ jobs: run: | "CGO_LDFLAGS=-L$env:TMP" >> $env:GITHUB_ENV "$env:TMP" >> $env:GITHUB_PATH - - name: Skip Avro plugin & test (windows) - if: matrix.os == 'windows-latest' - run: | - "SKIP_PLUGIN_AVRO=1" >> $env:GITHUB_ENV - name: Test (unit) if: matrix.os != 'ubuntu-latest' run: make test diff --git a/Makefile b/Makefile index 0a6582e20..f9a60549c 100755 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ PACT_CLI="docker run --rm -v ${PWD}:${PWD} -e PACT_BROKER_BASE_URL=$(DOCKER_HOST PLUGIN_PACT_PROTOBUF_VERSION=0.3.15 PLUGIN_PACT_CSV_VERSION=0.0.6 PLUGIN_PACT_MATT_VERSION=0.1.1 -PLUGIN_PACT_AVRO_VERSION=0.0.5 +PLUGIN_PACT_AVRO_VERSION=0.0.6 GO_VERSION?=1.22 ci:: docker deps clean bin test pact @@ -89,12 +89,10 @@ download_plugins: else \ echo "--- 🐿 Pact matt-$(PLUGIN_PACT_MATT_VERSION) already installed"; \ fi; \ - if [ -z $$SKIP_PLUGIN_AVRO ]; then\ - if [ ! -f ~/.pact/plugins/avro-$(PLUGIN_PACT_AVRO_VERSION)/bin/pact-avro-plugin ]; then \ - ~/.pact/bin/pact-plugin-cli -y install https://github.com/austek/pact-avro-plugin/releases/tag/v$(PLUGIN_PACT_AVRO_VERSION); \ - else \ - echo "--- 🐿 Pact avro-$(PLUGIN_PACT_AVRO_VERSION) already installed"; \ - fi; \ + if [ ! -f ~/.pact/plugins/avro-$(PLUGIN_PACT_AVRO_VERSION)/bin/pact-avro-plugin ]; then \ + ~/.pact/bin/pact-plugin-cli -y install https://github.com/austek/pact-avro-plugin/releases/tag/v$(PLUGIN_PACT_AVRO_VERSION); \ + else \ + echo "--- 🐿 Pact avro-$(PLUGIN_PACT_AVRO_VERSION) already installed"; \ fi; \ fi diff --git a/examples/avro/avro_consumer_test.go b/examples/avro/avro_consumer_test.go index 15613893e..6483ee98d 100644 --- a/examples/avro/avro_consumer_test.go +++ b/examples/avro/avro_consumer_test.go @@ -22,18 +22,17 @@ import ( var dir, _ = os.Getwd() func TestAvroHTTP(t *testing.T) { - 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) + 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", strings.ReplaceAll(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", @@ -41,28 +40,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.6", + }). + 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 38779439c..c7f957436 100644 --- a/examples/avro/avro_provider_test.go +++ b/examples/avro/avro_provider_test.go @@ -21,25 +21,24 @@ var dir, _ = os.Getwd() var pactDir = fmt.Sprintf("%s/../pacts", dir) func TestAvroHTTPProvider(t *testing.T) { - if os.Getenv("SKIP_PLUGIN_AVRO") != "1" { - httpPort, _ := utils.GetFreePort() + 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) { From 3b6ae5d68671a4e81f0da2d57fc79844dc29b663 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Fri, 30 Aug 2024 19:44:26 +0100 Subject: [PATCH 2/4] chore: update docker-compose to docker compose (v2 deprecation) --- Makefile | 2 +- scripts/pact.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f9a60549c..7f90ddbb2 100755 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ fake_pact: docker: @echo "--- 🛠 Starting docker" - docker-compose up -d + docker compose up -d docker_build: docker build -f Dockerfile --build-arg GO_VERSION=${GO_VERSION} -t pactfoundation/pact-go-test . diff --git a/scripts/pact.ps1 b/scripts/pact.ps1 index 8f0fd43e7..45ac2f296 100644 --- a/scripts/pact.ps1 +++ b/scripts/pact.ps1 @@ -69,7 +69,7 @@ foreach ($package in $packages) { # Run integration tests Write-Host "--> Testing E2E examples" Write-Host "Running consumer tests" -docker-compose up -d +docker compose up -d go test -tags=consumer -count=1 github.com/pact-foundation/pact-go/examples/... -run TestExample if ($LastExitCode -ne 0) { Write-Host "ERROR: Test failed, logging failure" From 2d6b6b1091727f1816b0e8721e33b0bf2eb0237c Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Wed, 4 Sep 2024 14:12:24 +0100 Subject: [PATCH 3/4] fix: bump libpact_ffi to 0.4.23 --- installer/installer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/installer.go b/installer/installer.go index 3822c4026..3f59f2944 100644 --- a/installer/installer.go +++ b/installer/installer.go @@ -387,7 +387,7 @@ const ( var packages = map[string]packageInfo{ FFIPackage: { libName: "libpact_ffi", - version: "0.4.22", + version: "0.4.23", semverRange: ">= 0.4.0, < 1.0.0", }, } From 879ccda5bc8a61a69a019ba559a553728ea4ba40 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Wed, 4 Sep 2024 14:38:29 +0100 Subject: [PATCH 4/4] chore: remove signal handler code --- internal/native/message_server.go | 1 - internal/native/mock_server.go | 1 - internal/native/signal.go | 87 ------------------------------- internal/native/verifier.go | 1 - 4 files changed, 90 deletions(-) delete mode 100644 internal/native/signal.go diff --git a/internal/native/message_server.go b/internal/native/message_server.go index 86936320d..31629ba84 100644 --- a/internal/native/message_server.go +++ b/internal/native/message_server.go @@ -237,7 +237,6 @@ func (m *MessageServer) UsingPlugin(pluginName string, pluginVersion string) err defer free(cPluginVersion) r := C.pactffi_using_plugin(m.messagePact.handle, cPluginName, cPluginVersion) - InstallSignalHandlers() // 1 - A general panic was caught. // 2 - Failed to load the plugin. diff --git a/internal/native/mock_server.go b/internal/native/mock_server.go index 1444cb564..2429301c1 100644 --- a/internal/native/mock_server.go +++ b/internal/native/mock_server.go @@ -398,7 +398,6 @@ func (m *MockServer) UsingPlugin(pluginName string, pluginVersion string) error defer free(cPluginVersion) r := C.pactffi_using_plugin(m.pact.handle, cPluginName, cPluginVersion) - InstallSignalHandlers() // 1 - A general panic was caught. // 2 - Failed to load the plugin. diff --git a/internal/native/signal.go b/internal/native/signal.go deleted file mode 100644 index 8757e47d7..000000000 --- a/internal/native/signal.go +++ /dev/null @@ -1,87 +0,0 @@ -//go:build cgo -// +build cgo - -package native - -/* -#if defined(__APPLE__) || defined(__linux__) -// https://github.com/wailsapp/wails/pull/2152/files#diff-d4a0fa73df7b0ab971e550f95249e358b634836e925ace96f7400480916ac09e -#include -#include -#include -#include - -static void fix_signal(int signum) -{ - struct sigaction st; - - if (sigaction(signum, NULL, &st) < 0) { - goto fix_signal_error; - } - st.sa_flags |= SA_ONSTACK; - if (sigaction(signum, &st, NULL) < 0) { - goto fix_signal_error; - } - return; -fix_signal_error: - fprintf(stderr, "error fixing handler for signal %d, please " - "report this issue to " - "https://github.com/pact-foundation/pact-go: %s\n", - signum, strerror(errno)); -} - -static void install_signal_handlers() -{ -#if defined(SIGCHLD) - fix_signal(SIGCHLD); -#endif -#if defined(SIGHUP) - fix_signal(SIGHUP); -#endif -#if defined(SIGINT) - fix_signal(SIGINT); -#endif -#if defined(SIGQUIT) - fix_signal(SIGQUIT); -#endif -#if defined(SIGABRT) - fix_signal(SIGABRT); -#endif -#if defined(SIGFPE) - fix_signal(SIGFPE); -#endif -#if defined(SIGTERM) - fix_signal(SIGTERM); -#endif -#if defined(SIGBUS) - fix_signal(SIGBUS); -#endif -#if defined(SIGSEGV) - fix_signal(SIGSEGV); -#endif -#if defined(SIGXCPU) - fix_signal(SIGXCPU); -#endif -#if defined(SIGXFSZ) - fix_signal(SIGXFSZ); -#endif -} -#else - static void install_signal_handlers() - { - } -#endif -*/ -import "C" -import ( - "os" - "runtime" -) - -func InstallSignalHandlers() { - if os.Getenv("PACT_GO_INSTALL_SIGNAL_HANDLERS") != "0" { - if runtime.GOOS != "windows" { - C.install_signal_handlers() - } - } -} diff --git a/internal/native/verifier.go b/internal/native/verifier.go index 26d41fd53..3f03df269 100644 --- a/internal/native/verifier.go +++ b/internal/native/verifier.go @@ -195,7 +195,6 @@ func (v *Verifier) SetPublishOptions(providerVersion string, buildUrl string, pr func (v *Verifier) Execute() error { // TODO: Validate - InstallSignalHandlers() result := C.pactffi_verifier_execute(v.handle) /// | Error | Description |