Skip to content

Commit

Permalink
test: renable avro windows
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Aug 30, 2024
1 parent 07d2009 commit a19fd06
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 58 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
12 changes: 5 additions & 7 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 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

0 comments on commit a19fd06

Please sign in to comment.