Skip to content

Commit

Permalink
Merge pull request #451 from pact-foundation/test/enable_avro
Browse files Browse the repository at this point in the history
fix: update libpact_ffi to 0.4.23 + enable avro (windows)
  • Loading branch information
YOU54F authored Sep 4, 2024
2 parents 07d2009 + 879ccda commit ab5aa52
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 151 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 6 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 .
Expand Down Expand Up @@ -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

Expand Down
63 changes: 31 additions & 32 deletions examples/avro/avro_consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,47 +22,46 @@ 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",
"id": "matching(number, 1)",
"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) {
Expand Down
29 changes: 14 additions & 15 deletions examples/avro/avro_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}
Expand Down
1 change: 0 additions & 1 deletion internal/native/message_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion internal/native/mock_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
87 changes: 0 additions & 87 deletions internal/native/signal.go

This file was deleted.

1 change: 0 additions & 1 deletion internal/native/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
2 changes: 1 addition & 1 deletion scripts/pact.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit ab5aa52

Please sign in to comment.