Skip to content

Commit

Permalink
Merge pull request #443 from YOU54F/ci/win-runners
Browse files Browse the repository at this point in the history
ci: add windows runners
  • Loading branch information
YOU54F authored Jul 31, 2024
2 parents 99d6f4b + f7d3a81 commit 6b525b4
Show file tree
Hide file tree
Showing 19 changed files with 303 additions and 108 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
1.21.x,
1.22.x,
]
os: [ubuntu-latest, macos-12, macos-14]
os: [ubuntu-latest, macos-12, macos-14, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
Expand All @@ -43,15 +43,26 @@ jobs:
- name: Test
if: matrix.os == 'ubuntu-latest'
run: APP_BRANCH=${APP_REF:11} DOCKER_GATEWAY_HOST=172.17.0.1 DOCKER_HOST_HTTP="http://172.17.0.1" make
- name: Set CGO_LDFLAGS / pact_ffi lib on PATH
if: matrix.os == 'windows-latest'
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
- name: Test (pact)
if: matrix.os != 'ubuntu-latest'
run: make pact_local
- name: Install goveralls
if: matrix.os != 'windows-latest'
run: go install github.com/mattn/goveralls@latest
- name: Send coverage
if: matrix.os != 'windows-latest'
run: goveralls -coverprofile=coverage.txt -service=github -parallel
- uses: actions/upload-artifact@v4
with:
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ PLUGIN_PACT_AVRO_VERSION=0.0.5

GO_VERSION?=1.22
ci:: docker deps clean bin test pact
PACT_DOWNLOAD_DIR=/tmp
ifeq ($(OS),Windows_NT)
PACT_DOWNLOAD_DIR=$$TMP
endif

# Run the ci target from a developer machine with the environment variables
# set as if it was on Travis CI.
Expand Down Expand Up @@ -61,10 +65,6 @@ clean:
rm -rf build output dist examples/pacts

deps: download_plugins
@echo "--- 🐿 Fetching build dependencies "
cd /tmp; \
go install github.com/mitchellh/gox@latest; \
cd -

download_plugins:
@echo "--- 🐿 Installing plugins"; \
Expand Down Expand Up @@ -106,7 +106,7 @@ cli:

install: bin
echo "--- 🐿 Installing Pact FFI dependencies"
./build/pact-go -l DEBUG install --libDir /tmp
./build/pact-go -l DEBUG install --libDir $(PACT_DOWNLOAD_DIR)

pact: clean install docker
@echo "--- 🔨 Running Pact examples"
Expand Down
3 changes: 2 additions & 1 deletion consumer/http_v4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package consumer
import (
"fmt"
"os"
"strings"
"testing"

"github.com/pact-foundation/pact-go/v2/matchers"
Expand Down Expand Up @@ -51,7 +52,7 @@ func TestHttpV4TypeSystem(t *testing.T) {
assert.Error(t, err)

dir, _ := os.Getwd()
path := fmt.Sprintf("%s/pact_plugin.proto", dir)
path := fmt.Sprintf("%s/pact_plugin.proto", strings.ReplaceAll(dir, "\\", "/"))

err = p.AddInteraction().
Given("some state").
Expand Down
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
7 changes: 4 additions & 3 deletions examples/grpc/grpc_consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"time"

Expand All @@ -29,7 +30,7 @@ func TestGetFeatureSuccess(t *testing.T) {
log.SetLogLevel("DEBUG")

dir, _ := os.Getwd()
path := fmt.Sprintf("%s/routeguide/route_guide.proto", dir)
path := fmt.Sprintf("%s/routeguide/route_guide.proto", strings.ReplaceAll(dir, "\\", "/"))

grpcInteraction := `{
"pact:proto": "` + path + `",
Expand Down Expand Up @@ -102,7 +103,7 @@ func TestGetFeatureError(t *testing.T) {
})

dir, _ := os.Getwd()
path := fmt.Sprintf("%s/routeguide/route_guide.proto", dir)
path := fmt.Sprintf("%s/routeguide/route_guide.proto", strings.ReplaceAll(dir, "\\", "/"))

grpcInteraction := `{
"pact:proto": "` + path + `",
Expand Down Expand Up @@ -167,7 +168,7 @@ func TestSaveFeature(t *testing.T) {
log.SetLogLevel("INFO")

dir, _ := os.Getwd()
path := fmt.Sprintf("%s/routeguide/route_guide.proto", dir)
path := fmt.Sprintf("%s/routeguide/route_guide.proto", strings.ReplaceAll(dir, "\\", "/"))

grpcInteraction := `{
"pact:proto": "` + path + `",
Expand Down
3 changes: 2 additions & 1 deletion examples/protobuf-message/protobuf_consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"

message "github.com/pact-foundation/pact-go/v2/message/v4"
Expand All @@ -23,7 +24,7 @@ func TestPluginMessageConsumer(t *testing.T) {
})

dir, _ := os.Getwd()
path := fmt.Sprintf("%s/../grpc/routeguide/route_guide.proto", dir)
path := fmt.Sprintf("%s/../grpc/routeguide/route_guide.proto", strings.ReplaceAll(dir, "\\", "/"))

protoMessage := `{
"pact:proto": "` + path + `",
Expand Down
7 changes: 7 additions & 0 deletions internal/native/c_types_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build darwin || linux

package native

import "C"

type CUlong = C.ulong
7 changes: 7 additions & 0 deletions internal/native/c_types_win.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build windows

package native

import "C"

type CUlong = C.ulonglong
6 changes: 3 additions & 3 deletions internal/native/message_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (m *Message) WithRequestBinaryContents(body []byte) *Message {
defer free(cHeader)

// TODO: handle response
res := C.pactffi_with_binary_file(m.handle, C.int(INTERACTION_PART_REQUEST), cHeader, (*C.uchar)(unsafe.Pointer(&body[0])), C.ulong(len(body)))
res := C.pactffi_with_binary_file(m.handle, C.int(INTERACTION_PART_REQUEST), cHeader, (*C.uchar)(unsafe.Pointer(&body[0])), CUlong(len(body)))

log.Println("[DEBUG] WithRequestBinaryContents - pactffi_with_binary_file returned", bool(res))

Expand All @@ -183,7 +183,7 @@ func (m *Message) WithRequestBinaryContentType(contentType string, body []byte)
defer free(cHeader)

// TODO: handle response
res := C.pactffi_with_binary_file(m.handle, C.int(INTERACTION_PART_REQUEST), cHeader, (*C.uchar)(unsafe.Pointer(&body[0])), C.ulong(len(body)))
res := C.pactffi_with_binary_file(m.handle, C.int(INTERACTION_PART_REQUEST), cHeader, (*C.uchar)(unsafe.Pointer(&body[0])), CUlong(len(body)))

log.Println("[DEBUG] WithRequestBinaryContents - pactffi_with_binary_file returned", res)

Expand All @@ -203,7 +203,7 @@ func (m *Message) WithResponseBinaryContents(body []byte) *Message {
defer free(cHeader)

// TODO: handle response
C.pactffi_with_binary_file(m.handle, C.int(INTERACTION_PART_RESPONSE), cHeader, (*C.uchar)(unsafe.Pointer(&body[0])), C.ulong(len(body)))
C.pactffi_with_binary_file(m.handle, C.int(INTERACTION_PART_RESPONSE), cHeader, (*C.uchar)(unsafe.Pointer(&body[0])), CUlong(len(body)))

return m
}
Expand Down
11 changes: 6 additions & 5 deletions internal/native/message_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
l "log"
"os"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -218,7 +219,7 @@ func TestGetPluginSyncMessageContentsAsBytes(t *testing.T) {
i := m.NewSyncMessageInteraction("grpc interaction")

dir, _ := os.Getwd()
path := fmt.Sprintf("%s/pact_plugin.proto", dir)
path := fmt.Sprintf("%s/pact_plugin.proto", strings.ReplaceAll(dir, "\\", "/"))

grpcInteraction := `{
"pact:proto": "` + path + `",
Expand Down Expand Up @@ -276,7 +277,7 @@ func TestGetPluginSyncMessageContentsAsBytes_EmptyResponse(t *testing.T) {
i := m.NewSyncMessageInteraction("grpc interaction")

dir, _ := os.Getwd()
path := fmt.Sprintf("%s/pact_plugin.proto", dir)
path := fmt.Sprintf("%s/pact_plugin.proto", strings.ReplaceAll(dir, "\\", "/"))

grpcInteraction := `{
"pact:proto": "` + path + `",
Expand Down Expand Up @@ -322,7 +323,7 @@ func TestGetPluginAsyncMessageContentsAsBytes(t *testing.T) {
i := m.NewAsyncMessageInteraction("grpc interaction")

dir, _ := os.Getwd()
path := fmt.Sprintf("%s/pact_plugin.proto", dir)
path := fmt.Sprintf("%s/pact_plugin.proto", strings.ReplaceAll(dir, "\\", "/"))

protobufInteraction := `{
"pact:proto": "` + path + `",
Expand Down Expand Up @@ -363,7 +364,7 @@ func TestGrpcPluginInteraction(t *testing.T) {
i := m.NewSyncMessageInteraction("grpc interaction")

dir, _ := os.Getwd()
path := fmt.Sprintf("%s/pact_plugin.proto", dir)
path := fmt.Sprintf("%s/pact_plugin.proto", strings.ReplaceAll(dir, "\\", "/"))

grpcInteraction := `{
"pact:proto": "` + path + `",
Expand Down Expand Up @@ -441,7 +442,7 @@ func TestGrpcPluginInteraction_ErrorResponse(t *testing.T) {
i := m.NewSyncMessageInteraction("grpc interaction")

dir, _ := os.Getwd()
path := fmt.Sprintf("%s/pact_plugin.proto", dir)
path := fmt.Sprintf("%s/pact_plugin.proto", strings.ReplaceAll(dir, "\\", "/"))

grpcInteraction := `{
"pact:proto": "` + path + `",
Expand Down
6 changes: 3 additions & 3 deletions internal/native/mock_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ func (i *Interaction) withHeaders(part interactionPart, valueOrMatcher map[strin
value := stringFromInterface(header)
cValue := C.CString(value)

C.pactffi_with_header_v2(i.handle, C.int(part), cName, C.ulong(0), cValue)
C.pactffi_with_header_v2(i.handle, C.int(part), cName, CUlong(0), cValue)

free(cValue)
}
Expand All @@ -560,7 +560,7 @@ func (i *Interaction) WithQuery(valueOrMatcher map[string][]interface{}) *Intera
value := stringFromInterface(v)
cValue := C.CString(value)

C.pactffi_with_query_parameter_v2(i.handle, cName, C.ulong(idx), cValue)
C.pactffi_with_query_parameter_v2(i.handle, cName, CUlong(idx), cValue)

free(cValue)
}
Expand Down Expand Up @@ -616,7 +616,7 @@ func (i *Interaction) withBinaryBody(contentType string, body []byte, part inter
cHeader := C.CString(contentType)
defer free(cHeader)

C.pactffi_with_binary_file(i.handle, C.int(part), cHeader, (*C.uchar)(unsafe.Pointer(&body[0])), C.ulong(len(body)))
C.pactffi_with_binary_file(i.handle, C.int(part), cHeader, (*C.uchar)(unsafe.Pointer(&body[0])), CUlong(len(body)))

return i
}
Expand Down
Loading

0 comments on commit 6b525b4

Please sign in to comment.