From 83468486a927facb48449a5b71df774e4b1d711f Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Sun, 30 Jun 2024 17:21:19 +0100 Subject: [PATCH] ci(test): test with CGO_ENABLED 0/1 --- .github/workflows/test.yml | 68 +++++--- Makefile | 30 +++- examples/provider_test.go | 251 ------------------------------ examples/provider_test_http.go | 191 +++++++++++++++++++++++ examples/provider_test_message.go | 91 +++++++++++ internal/native/message_server.go | 10 +- internal/native/mock_server.go | 11 +- internal/native/verifier.go | 11 +- 8 files changed, 365 insertions(+), 298 deletions(-) delete mode 100644 examples/provider_test.go create mode 100644 examples/provider_test_http.go create mode 100644 examples/provider_test_message.go diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9bf745fe8..90ebd24ab 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,6 +26,7 @@ jobs: 1.22.x, ] os: [ubuntu-latest, macos-12, macos-14, windows-latest] + cgo: [0,1] runs-on: ${{ matrix.os }} steps: - name: Checkout code @@ -38,6 +39,9 @@ jobs: with: distribution: 'zulu' java-version: '17' + - name: "Set CGO_ENABLED: ${{ matrix.cgo }}" + run: | + "CGO_ENABLED=${{ matrix.cgo }}" >> $env:GITHUB_ENV - if: matrix.os == 'macos-14' run: brew install protobuf - name: Test @@ -85,6 +89,7 @@ jobs: variant: - debian - alpine + cgo: [0,1] steps: - uses: actions/checkout@v4 - name: Set up Docker Buildx @@ -93,32 +98,47 @@ jobs: with: platforms: ${{ matrix.arch }} - - name: Build ${{ matrix.arch }} dockerfile - run: | - docker build \ - --platform ${{ matrix.arch }} \ - --build-arg VERSION=${{ matrix.go-version }} \ - -f Dockerfile.${{ matrix.variant }} \ - -t pactfoundation/pact-go-test-${{ matrix.go-version }} . + - name: Test (unit) + run: make docker_test + env: + DOCKER_ARCH: ${{ matrix.arch }} + GO_VERSION: ${{ matrix.go-version }} + VARIANT: ${{ matrix.variant }} + CGO_ENABLED: ${{ matrix.cgo }} + - name: Test (pact) + run: make docker_pact + env: + DOCKER_ARCH: ${{ matrix.arch }} + GO_VERSION: ${{ matrix.go-version }} + VARIANT: ${{ matrix.variant }} + CGO_ENABLED: ${{ matrix.cgo }} + + # - name: Build ${{ matrix.arch }} dockerfile + # run: | + # docker build \ + # --platform ${{ matrix.arch }} \ + # --build-arg VERSION=${{ matrix.go-version }} \ + # -f Dockerfile.${{ matrix.variant }} \ + # -t pactfoundation/pact-go-test-${{ matrix.go-version }} . - - name: Test - ${{ matrix.arch }} - if: matrix.arch == 'amd64' - run: | - docker run \ - --platform linux/${{ matrix.arch }} \ - -e LOG_LEVEL=${{ env.LOG_LEVEL }} \ - -e PACT_LD_LIBRARY_PATH=${{ env.PACT_LD_LIBRARY_PATH }} \ - --rm pactfoundation/pact-go-test-${{ matrix.go-version }} /bin/sh -c 'make test && make pact_local' + # - name: Test - ${{ matrix.arch }} + # if: matrix.arch == 'amd64' + # run: | + # docker run \ + # --platform linux/${{ matrix.arch }} \ + # -e LOG_LEVEL=${{ env.LOG_LEVEL }} \ + # -e PACT_LD_LIBRARY_PATH=${{ env.PACT_LD_LIBRARY_PATH }} \ + # --rm pactfoundation/pact-go-test-${{ matrix.go-version }} /bin/sh -c 'make test && make pact_local' - - name: Test - ${{ matrix.arch }} - if: matrix.arch == 'arm64' - run: | - docker run \ - --platform linux/${{ matrix.arch }} \ - -e LOG_LEVEL=${{ env.LOG_LEVEL }} \ - -e PACT_LD_LIBRARY_PATH=${{ env.PACT_LD_LIBRARY_PATH }} \ - -e SKIP_RACE=true \ - --rm pactfoundation/pact-go-test-${{ matrix.go-version }} /bin/sh -c 'make test && make pact_local' + # - name: Test - ${{ matrix.arch }} + # if: matrix.arch == 'arm64' + # run: | + # docker run \ + # --platform linux/${{ matrix.arch }} \ + # -e LOG_LEVEL=${{ env.LOG_LEVEL }} \ + # -e PACT_LD_LIBRARY_PATH=${{ env.PACT_LD_LIBRARY_PATH }} \ + # -e SKIP_RACE=true \ + # --rm pactfoundation/pact-go-test-${{ matrix.go-version }} /bin/sh -c 'make test && make pact_local' finish: needs: [test,test-containers] diff --git a/Makefile b/Makefile index 6406ed490..548486104 100755 --- a/Makefile +++ b/Makefile @@ -15,7 +15,12 @@ PACT_DOWNLOAD_DIR=/tmp ifeq ($(OS),Windows_NT) PACT_DOWNLOAD_DIR=$$TMP endif - +CGO_ENABLED?=1 +ifeq ($(CGO_ENABLED),0) + SKIP_RACE=true +endif +SKIP_RACE?=false +DOCKER_ARCH?=arm64 # Run the ci target from a developer machine with the environment variables # set as if it was on Travis CI. # Use this for quick feedback when playing around with your workflows. @@ -41,7 +46,10 @@ docker_build: docker_test: docker_build docker run \ + --platform linux/$(DOCKER_ARCH) \ -e LOG_LEVEL=INFO \ + -e SKIP_RACE=$(SKIP_RACE) \ + -e CGO_ENABLED=$(CGO_ENABLED) \ -e PACT_LD_LIBRARY_PATH=$(PACT_DOWNLOAD_DIR) \ --rm \ -it \ @@ -49,7 +57,10 @@ docker_test: docker_build /bin/sh -c "make test" docker_pact: docker_build docker run \ + --platform linux/$(DOCKER_ARCH) \ -e LOG_LEVEL=INFO \ + -e SKIP_RACE=$(SKIP_RACE) \ + -e CGO_ENABLED=$(CGO_ENABLED) \ -e PACT_LD_LIBRARY_PATH=$(PACT_DOWNLOAD_DIR) \ --rm \ -it \ @@ -57,6 +68,9 @@ docker_pact: docker_build /bin/sh -c "make pact_local" docker_shell: docker_build docker run \ + --platform linux/$(DOCKER_ARCH) \ + -e SKIP_RACE=$(SKIP_RACE) \ + -e CGO_ENABLED=$(CGO_ENABLED) \ -e LOG_LEVEL=INFO \ -e PACT_LD_LIBRARY_PATH=$(PACT_DOWNLOAD_DIR) \ -v $$PWD:/go/src/github.com/pact-foundation/pact-go \ @@ -117,13 +131,13 @@ install: bin pact: clean install docker @echo "--- 🔨 Running Pact examples" - go test -v $(SKIP_RACE) -tags=consumer -count=1 github.com/pact-foundation/pact-go/v2/examples/... + go test -v $(RACE) -tags=consumer -count=1 github.com/pact-foundation/pact-go/v2/examples/... make publish - go test -v $(SKIP_RACE) -timeout=30s -tags=provider -count=1 github.com/pact-foundation/pact-go/v2/examples/... -pact_local: clean download_plugins install + go test -v $(RACE) -timeout=30s -tags=provider -count=1 github.com/pact-foundation/pact-go/v2/examples/... +pact_local: clean deps install @echo "--- 🔨 Running Pact examples" - go test -v $(SKIP_RACE) -tags=consumer -count=1 github.com/pact-foundation/pact-go/v2/examples/... - SKIP_PUBLISH=true go test -v $(SKIP_RACE) -timeout=30s -tags=provider -count=1 github.com/pact-foundation/pact-go/v2/examples/... + go test -v $(RACE) -tags=consumer -count=1 github.com/pact-foundation/pact-go/v2/examples/... + SKIP_PUBLISH=true go test -v $(RACE) -timeout=30s -tags=provider -count=1 github.com/pact-foundation/pact-go/v2/examples/... publish: @echo "-- 📃 Publishing pacts" @@ -133,9 +147,9 @@ release: echo "--- 🚀 Releasing it" "$(CURDIR)/scripts/release.sh" -RACE?='-race' +RACE?=-race -ifdef SKIP_RACE +ifeq ($(SKIP_RACE),true) RACE= endif diff --git a/examples/provider_test.go b/examples/provider_test.go deleted file mode 100644 index 99dd5ee1e..000000000 --- a/examples/provider_test.go +++ /dev/null @@ -1,251 +0,0 @@ -//go:build provider -// +build provider - -// Package main contains a runnable Provider Pact test example. -package main - -import ( - "fmt" - l "log" - "net/http" - "os" - // "path/filepath" - // "testing" - // "github.com/hashicorp/logutils" - // "github.com/pact-foundation/pact-go/v2/log" - // "github.com/pact-foundation/pact-go/v2/message" - // "github.com/pact-foundation/pact-go/v2/models" - // "github.com/pact-foundation/pact-go/v2/provider" - // "github.com/pact-foundation/pact-go/v2/version" - // "github.com/stretchr/testify/assert" -) - -var dir, _ = os.Getwd() -var pactDir = fmt.Sprintf("%s/pacts", dir) - -var requestFilterCalled = false -var stateHandlerCalled = false - -// func TestV3HTTPProvider(t *testing.T) { -// logLevel := os.Getenv("LOG_LEVEL") -// if logLevel == "" { -// logLevel = "TRACE" -// } -// log.SetLogLevel(logutils.LogLevel(logLevel)) -// version.CheckVersion("/tmp") - -// // Start provider API in the background -// go startServer() - -// verifier := provider.NewVerifier() - -// // Authorization middleware -// // This is your chance to modify the request before it hits your provider -// // NOTE: this should be used very carefully, as it has the potential to -// // _change_ the contract -// f := func(next http.Handler) http.Handler { -// return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { -// l.Println("[DEBUG] HOOK request filter") -// requestFilterCalled = true -// r.Header.Add("Authorization", "Bearer 1234-dynamic-value") -// next.ServeHTTP(w, r) -// }) -// } - -// // Verify the Provider with local Pact Files - -// if os.Getenv("SKIP_PUBLISH") != "true" { -// err := verifier.VerifyProvider(t, provider.VerifyRequest{ -// ProviderBaseURL: "http://127.0.0.1:8111", -// Provider: "V3Provider", -// ProviderVersion: os.Getenv("APP_SHA"), -// BrokerURL: os.Getenv("PACT_BROKER_BASE_URL"), -// ConsumerVersionSelectors: []provider.Selector{ -// &provider.ConsumerVersionSelector{ -// Tag: "master", -// }, -// &provider.ConsumerVersionSelector{ -// Tag: "prod", -// }, -// }, -// PublishVerificationResults: true, -// RequestFilter: f, -// BeforeEach: func() error { -// l.Println("[DEBUG] HOOK before each") -// return nil -// }, -// AfterEach: func() error { -// l.Println("[DEBUG] HOOK after each") -// return nil -// }, -// StateHandlers: models.StateHandlers{ -// "User foo exists": func(setup bool, s models.ProviderState) (models.ProviderStateResponse, error) { -// stateHandlerCalled = true - -// if setup { -// l.Println("[DEBUG] HOOK calling user foo exists state handler", s) -// } else { -// l.Println("[DEBUG] HOOK teardown the 'User foo exists' state") -// } - -// // ... do something, such as create "foo" in the database - -// // Optionally (if there are generators in the pact) return provider state values to be used in the verification -// return models.ProviderStateResponse{"uuid": "1234"}, nil -// }, -// }, -// DisableColoredOutput: true, -// }) -// assert.NoError(t, err) -// assert.True(t, requestFilterCalled) -// assert.True(t, stateHandlerCalled) -// } else { -// err := verifier.VerifyProvider(t, provider.VerifyRequest{ -// ProviderBaseURL: "http://127.0.0.1:8111", -// Provider: "V3Provider", -// PactFiles: []string{ -// filepath.ToSlash(fmt.Sprintf("%s/PactGoV3Consumer-V3Provider.json", pactDir)), -// filepath.ToSlash(fmt.Sprintf("%s/PactGoV2ConsumerMatch-V2ProviderMatch.json", pactDir)), -// }, -// RequestFilter: f, -// BeforeEach: func() error { -// l.Println("[DEBUG] HOOK before each") -// return nil -// }, -// AfterEach: func() error { -// l.Println("[DEBUG] HOOK after each") -// return nil -// }, -// StateHandlers: models.StateHandlers{ -// "User foo exists": func(setup bool, s models.ProviderState) (models.ProviderStateResponse, error) { -// stateHandlerCalled = true - -// if setup { -// l.Println("[DEBUG] HOOK calling user foo exists state handler", s) -// } else { -// l.Println("[DEBUG] HOOK teardown the 'User foo exists' state") -// } - -// // ... do something, such as create "foo" in the database - -// // Optionally (if there are generators in the pact) return provider state values to be used in the verification -// return models.ProviderStateResponse{"uuid": "1234"}, nil -// }, -// }, -// DisableColoredOutput: true, -// }) -// assert.NoError(t, err) -// assert.True(t, requestFilterCalled) -// assert.True(t, stateHandlerCalled) -// } - -// } - -// func TestV3MessageProvider(t *testing.T) { -// logLevel := os.Getenv("LOG_LEVEL") -// if logLevel == "" { -// logLevel = "TRACE" -// } -// log.SetLogLevel(logutils.LogLevel(logLevel)) -// var user *User - -// verifier := provider.NewVerifier() - -// // Map test descriptions to message producer (handlers) -// functionMappings := message.Handlers{ -// "a user event": func([]models.ProviderState) (message.Body, message.Metadata, error) { -// if user != nil { -// return user, message.Metadata{ -// "Content-Type": "application/json", -// }, nil -// } else { -// return models.ProviderStateResponse{ -// "message": "not found", -// }, nil, nil -// } -// }, -// } - -// // Setup any required states for the handlers -// stateMappings := models.StateHandlers{ -// "User with id 127 exists": func(setup bool, s models.ProviderState) (models.ProviderStateResponse, error) { -// if setup { -// user = &User{ -// ID: 127, -// Name: "Billy", -// Date: "2020-01-01", -// LastName: "Sampson", -// } -// } - -// return models.ProviderStateResponse{"id": user.ID}, nil -// }, -// } - -// // Verify the Provider with local Pact Files - -// if os.Getenv("SKIP_PUBLISH") != "true" { -// verifier.VerifyProvider(t, provider.VerifyRequest{ -// StateHandlers: stateMappings, -// Provider: "V3MessageProvider", -// ProviderVersion: os.Getenv("APP_SHA"), -// BrokerURL: os.Getenv("PACT_BROKER_BASE_URL"), -// MessageHandlers: functionMappings, -// }) -// } else { -// verifier.VerifyProvider(t, provider.VerifyRequest{ -// PactFiles: []string{filepath.ToSlash(fmt.Sprintf("%s/PactGoV3MessageConsumer-V3MessageProvider.json", pactDir))}, -// StateHandlers: stateMappings, -// Provider: "V3MessageProvider", -// MessageHandlers: functionMappings, -// }) -// } - -// } - -func startServer() { - mux := http.NewServeMux() - - mux.HandleFunc("/foobar", func(w http.ResponseWriter, req *http.Request) { - w.Header().Add("Content-Type", "application/json") - fmt.Fprintf(w, ` - { - "accountBalance": 123.76, - "datetime": "2020-01-01", - "equality": "a thing", - "id": 12, - "itemsMin": [ - "thereshouldbe3ofthese", - "thereshouldbe3ofthese", - "thereshouldbe3ofthese" - ], - "itemsMinMax": [ - 27, - 27, - 27, - 27, - 27 - ], - "lastName": "Sampson", - "name": "Billy", - "superstring": "foo", - "arrayContaining": [ - "string", - 1, - { - "foo": "bar" - } - ] - }`, - ) - }) - - l.Fatal(http.ListenAndServe("127.0.0.1:8111", mux)) -} - -type User struct { - ID int `json:"id" pact:"example=27"` - Name string `json:"name" pact:"example=billy"` - LastName string `json:"lastName" pact:"example=Sampson"` - Date string `json:"datetime" pact:"example=2020-01-01'T'08:00:45,format=yyyy-MM-dd'T'HH:mm:ss,generator=datetime"` -} diff --git a/examples/provider_test_http.go b/examples/provider_test_http.go new file mode 100644 index 000000000..425c35d7d --- /dev/null +++ b/examples/provider_test_http.go @@ -0,0 +1,191 @@ +//go:build provider +// +build provider + +// Package main contains a runnable Provider Pact test example. +package main + +import ( + "fmt" + l "log" + "net/http" + "os" + "path/filepath" + "testing" + + // "github.com/hashicorp/logutils" + // "github.com/pact-foundation/pact-go/v2/log" + + "github.com/pact-foundation/pact-go/v2/models" + "github.com/pact-foundation/pact-go/v2/provider" + "github.com/pact-foundation/pact-go/v2/version" + "github.com/stretchr/testify/assert" +) + +func TestV3HTTPProvider(t *testing.T) { + + var dir, _ = os.Getwd() + var pactDir = fmt.Sprintf("%s/pacts", dir) + + type User struct { + ID int `json:"id" pact:"example=27"` + Name string `json:"name" pact:"example=billy"` + LastName string `json:"lastName" pact:"example=Sampson"` + Date string `json:"datetime" pact:"example=2020-01-01'T'08:00:45,format=yyyy-MM-dd'T'HH:mm:ss,generator=datetime"` + } + + var requestFilterCalled = false + var stateHandlerCalled = false + + // logLevel := os.Getenv("LOG_LEVEL") + // if logLevel == "" { + // logLevel = "TRACE" + // } + // log.SetLogLevel(logutils.LogLevel(logLevel)) + version.CheckVersion("/tmp") + + // Start provider API in the background + go startServer() + + verifier := provider.NewVerifier() + + // Authorization middleware + // This is your chance to modify the request before it hits your provider + // NOTE: this should be used very carefully, as it has the potential to + // _change_ the contract + f := func(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + l.Println("[DEBUG] HOOK request filter") + requestFilterCalled = true + r.Header.Add("Authorization", "Bearer 1234-dynamic-value") + next.ServeHTTP(w, r) + }) + } + + // Verify the Provider with local Pact Files + + if os.Getenv("SKIP_PUBLISH") != "true" { + err := verifier.VerifyProvider(t, provider.VerifyRequest{ + ProviderBaseURL: "http://127.0.0.1:8111", + Provider: "V3Provider", + ProviderVersion: os.Getenv("APP_SHA"), + BrokerURL: os.Getenv("PACT_BROKER_BASE_URL"), + ConsumerVersionSelectors: []provider.Selector{ + &provider.ConsumerVersionSelector{ + Tag: "master", + }, + &provider.ConsumerVersionSelector{ + Tag: "prod", + }, + }, + PublishVerificationResults: true, + RequestFilter: f, + BeforeEach: func() error { + l.Println("[DEBUG] HOOK before each") + return nil + }, + AfterEach: func() error { + l.Println("[DEBUG] HOOK after each") + return nil + }, + StateHandlers: models.StateHandlers{ + "User foo exists": func(setup bool, s models.ProviderState) (models.ProviderStateResponse, error) { + stateHandlerCalled = true + + if setup { + l.Println("[DEBUG] HOOK calling user foo exists state handler", s) + } else { + l.Println("[DEBUG] HOOK teardown the 'User foo exists' state") + } + + // ... do something, such as create "foo" in the database + + // Optionally (if there are generators in the pact) return provider state values to be used in the verification + return models.ProviderStateResponse{"uuid": "1234"}, nil + }, + }, + DisableColoredOutput: true, + }) + assert.NoError(t, err) + assert.True(t, requestFilterCalled) + assert.True(t, stateHandlerCalled) + } else { + err := verifier.VerifyProvider(t, provider.VerifyRequest{ + ProviderBaseURL: "http://127.0.0.1:8111", + Provider: "V3Provider", + PactFiles: []string{ + filepath.ToSlash(fmt.Sprintf("%s/PactGoV3Consumer-V3Provider.json", pactDir)), + filepath.ToSlash(fmt.Sprintf("%s/PactGoV2ConsumerMatch-V2ProviderMatch.json", pactDir)), + }, + RequestFilter: f, + BeforeEach: func() error { + l.Println("[DEBUG] HOOK before each") + return nil + }, + AfterEach: func() error { + l.Println("[DEBUG] HOOK after each") + return nil + }, + StateHandlers: models.StateHandlers{ + "User foo exists": func(setup bool, s models.ProviderState) (models.ProviderStateResponse, error) { + stateHandlerCalled = true + + if setup { + l.Println("[DEBUG] HOOK calling user foo exists state handler", s) + } else { + l.Println("[DEBUG] HOOK teardown the 'User foo exists' state") + } + + // ... do something, such as create "foo" in the database + + // Optionally (if there are generators in the pact) return provider state values to be used in the verification + return models.ProviderStateResponse{"uuid": "1234"}, nil + }, + }, + DisableColoredOutput: true, + }) + assert.NoError(t, err) + assert.True(t, requestFilterCalled) + assert.True(t, stateHandlerCalled) + } + +} + +func startServer() { + mux := http.NewServeMux() + + mux.HandleFunc("/foobar", func(w http.ResponseWriter, req *http.Request) { + w.Header().Add("Content-Type", "application/json") + fmt.Fprintf(w, ` + { + "accountBalance": 123.76, + "datetime": "2020-01-01", + "equality": "a thing", + "id": 12, + "itemsMin": [ + "thereshouldbe3ofthese", + "thereshouldbe3ofthese", + "thereshouldbe3ofthese" + ], + "itemsMinMax": [ + 27, + 27, + 27, + 27, + 27 + ], + "lastName": "Sampson", + "name": "Billy", + "superstring": "foo", + "arrayContaining": [ + "string", + 1, + { + "foo": "bar" + } + ] + }`, + ) + }) + + l.Fatal(http.ListenAndServe("127.0.0.1:8111", mux)) +} diff --git a/examples/provider_test_message.go b/examples/provider_test_message.go new file mode 100644 index 000000000..5a03950b6 --- /dev/null +++ b/examples/provider_test_message.go @@ -0,0 +1,91 @@ +//go:build provider +// +build provider + +// Package main contains a runnable Provider Pact test example. +package main + +import ( + "fmt" + "os" + "path/filepath" + "testing" + + // "github.com/hashicorp/logutils" + // "github.com/pact-foundation/pact-go/v2/log" + + "github.com/pact-foundation/pact-go/v2/message" + "github.com/pact-foundation/pact-go/v2/models" + "github.com/pact-foundation/pact-go/v2/provider" +) + +func TestV3MessageProvider(t *testing.T) { + var dir, _ = os.Getwd() + var pactDir = fmt.Sprintf("%s/pacts", dir) + + type User struct { + ID int `json:"id" pact:"example=27"` + Name string `json:"name" pact:"example=billy"` + LastName string `json:"lastName" pact:"example=Sampson"` + Date string `json:"datetime" pact:"example=2020-01-01'T'08:00:45,format=yyyy-MM-dd'T'HH:mm:ss,generator=datetime"` + } + + // logLevel := os.Getenv("LOG_LEVEL") + // if logLevel == "" { + // logLevel = "TRACE" + // } + // log.SetLogLevel(logutils.LogLevel(logLevel)) + var user *User + + verifier := provider.NewVerifier() + + // Map test descriptions to message producer (handlers) + functionMappings := message.Handlers{ + "a user event": func([]models.ProviderState) (message.Body, message.Metadata, error) { + if user != nil { + return user, message.Metadata{ + "Content-Type": "application/json", + }, nil + } else { + return models.ProviderStateResponse{ + "message": "not found", + }, nil, nil + } + }, + } + + // Setup any required states for the handlers + stateMappings := models.StateHandlers{ + "User with id 127 exists": func(setup bool, s models.ProviderState) (models.ProviderStateResponse, error) { + if setup { + user = &User{ + ID: 127, + Name: "Billy", + Date: "2020-01-01", + LastName: "Sampson", + } + } + + return models.ProviderStateResponse{"id": user.ID}, nil + }, + } + + // Verify the Provider with local Pact Files + + if os.Getenv("SKIP_PUBLISH") != "true" { + verifier.VerifyProvider(t, provider.VerifyRequest{ + StateHandlers: stateMappings, + Provider: "V3MessageProvider", + ProviderVersion: os.Getenv("APP_SHA"), + BrokerURL: os.Getenv("PACT_BROKER_BASE_URL"), + MessageHandlers: functionMappings, + }) + } else { + verifier.VerifyProvider(t, provider.VerifyRequest{ + PactFiles: []string{filepath.ToSlash(fmt.Sprintf("%s/PactGoV3MessageConsumer-V3MessageProvider.json", pactDir))}, + StateHandlers: stateMappings, + Provider: "V3MessageProvider", + MessageHandlers: functionMappings, + }) + } + +} diff --git a/internal/native/message_server.go b/internal/native/message_server.go index 9368fe6f8..9f8dbc2c9 100644 --- a/internal/native/message_server.go +++ b/internal/native/message_server.go @@ -69,13 +69,13 @@ static void install_signal_handlers() } #endif */ -import "C" +// import "C" import ( "encoding/json" "errors" "fmt" "log" - "runtime" + // "runtime" "unsafe" ) @@ -266,9 +266,9 @@ func (m *Message) WithContents(part interactionPart, contentType string, body [] func (m *MessageServer) UsingPlugin(pluginName string, pluginVersion string) error { r := pactffi_using_plugin(m.messagePact.handle, pluginName, pluginVersion) - if runtime.GOOS != "windows" { - C.install_signal_handlers() - } + // if runtime.GOOS != "windows" { + // C.install_signal_handlers() + // } // 1 - A general panic was caught. // 2 - Failed to load the plugin. // 3 - Pact Handle is not valid. diff --git a/internal/native/mock_server.go b/internal/native/mock_server.go index ffa57a759..65827edb6 100644 --- a/internal/native/mock_server.go +++ b/internal/native/mock_server.go @@ -69,7 +69,7 @@ static void install_signal_handlers() } #endif */ -import "C" +// import "C" import ( "crypto/tls" "crypto/x509" @@ -77,7 +77,8 @@ import ( "fmt" "log" "os" - "runtime" + + // "runtime" "strings" ) @@ -435,9 +436,9 @@ func (m *MockServer) WithMetadata(namespace, k, v string) *MockServer { func (m *MockServer) UsingPlugin(pluginName string, pluginVersion string) error { r := pactffi_using_plugin(m.pact.handle, pluginName, pluginVersion) - if runtime.GOOS != "windows" { - C.install_signal_handlers() - } + // if runtime.GOOS != "windows" { + // C.install_signal_handlers() + // } // 1 - A general panic was caught. // 2 - Failed to load the plugin. // 3 - Pact Handle is not valid. diff --git a/internal/native/verifier.go b/internal/native/verifier.go index ccb2f7de5..495018c71 100644 --- a/internal/native/verifier.go +++ b/internal/native/verifier.go @@ -69,11 +69,12 @@ static void install_signal_handlers() } #endif */ -import "C" +// import "C" import ( "fmt" "log" - "runtime" + + // "runtime" "strings" ) @@ -189,9 +190,9 @@ func (v *Verifier) SetPublishOptions(providerVersion string, buildUrl string, pr func (v *Verifier) Execute() error { // TODO: Validate - if runtime.GOOS != "windows" { - C.install_signal_handlers() - } + // if runtime.GOOS != "windows" { + // C.install_signal_handlers() + // } result := pactffi_verifier_execute(v.handle) /// | Error | Description | /// |-------|-------------|