Skip to content

Commit

Permalink
chore(avro): windows - skip avro plugin as it fails to start
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Jul 25, 2024
1 parent d2f38cf commit de76480
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 43 deletions.
63 changes: 33 additions & 30 deletions examples/avro/avro_consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"net/url"
"os"
"strings"
"testing"

"github.com/pact-foundation/pact-go/v2/consumer"
Expand All @@ -21,45 +22,47 @@ 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",
"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.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) {
Expand Down
28 changes: 15 additions & 13 deletions examples/avro/avro_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit de76480

Please sign in to comment.