Skip to content

Commit

Permalink
test: remove windows plugin excludes as controlled by tags
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Jun 30, 2024
1 parent 88cbb0b commit de4446b
Show file tree
Hide file tree
Showing 14 changed files with 728 additions and 759 deletions.
54 changes: 26 additions & 28 deletions consumer/http_v4_test_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package consumer
import (
"fmt"
"os"
"runtime"
"strings"
"testing"

Expand All @@ -28,37 +27,36 @@ func TestHttpV4PluginTypeSystem(t *testing.T) {
})
assert.NoError(t, err)

if runtime.GOOS != "windows" {
dir, _ := os.Getwd()
path := fmt.Sprintf("%s/pact_plugin.proto", strings.ReplaceAll(dir, "\\", "/"))

err = p.AddInteraction().
Given("some state").
UponReceiving("some scenario").
UsingPlugin(PluginConfig{
Plugin: "protobuf",
Version: "0.3.15",
}).
WithRequest("GET", "/").
// WithRequest("GET", "/", func(b *V4InteractionWithPluginRequestBuilder) {
// b.PluginContents("application/protobufs", "")
// // TODO:
// }).
WillRespondWith(200, func(b *V4InteractionWithPluginResponseBuilder) {
b.
Header("Content-Type", S("application/protobufs")).
PluginContents("application/protobufs", `
dir, _ := os.Getwd()
path := fmt.Sprintf("%s/pact_plugin.proto", strings.ReplaceAll(dir, "\\", "/"))

err = p.AddInteraction().
Given("some state").
UponReceiving("some scenario").
UsingPlugin(PluginConfig{
Plugin: "protobuf",
Version: "0.3.15",
}).
WithRequest("GET", "/").
// WithRequest("GET", "/", func(b *V4InteractionWithPluginRequestBuilder) {
// b.PluginContents("application/protobufs", "")
// // TODO:
// }).
WillRespondWith(200, func(b *V4InteractionWithPluginResponseBuilder) {
b.
Header("Content-Type", S("application/protobufs")).
PluginContents("application/protobufs", `
{
"pact:proto": "`+path+`",
"pact:message-type": "InitPluginRequest"
}
`)
}).
ExecuteTest(t, func(msc MockServerConfig) error {
// <- normally run the actually test here.
}).
ExecuteTest(t, func(msc MockServerConfig) error {
// <- normally run the actually test here.

return nil
})
assert.Error(t, err)

return nil
})
assert.Error(t, err)
}
}
64 changes: 31 additions & 33 deletions examples/avro/avro_consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/http"
"net/url"
"os"
"runtime"
"strings"
"testing"

Expand All @@ -23,47 +22,46 @@ import (
var dir, _ = os.Getwd()

func TestAvroHTTP(t *testing.T) {
if runtime.GOOS != "windows" {
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.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
30 changes: 14 additions & 16 deletions examples/avro/avro_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/http"
"os"
"path/filepath"
"runtime"
"testing"

"github.com/pact-foundation/pact-go/v2/provider"
Expand All @@ -21,26 +20,25 @@ var dir, _ = os.Getwd()
var pactDir = fmt.Sprintf("%s/../pacts", dir)

func TestAvroHTTPProvider(t *testing.T) {
if runtime.GOOS != "windows" {

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
Loading

0 comments on commit de4446b

Please sign in to comment.