Skip to content

Commit 6b525b4

Browse files
authored
Merge pull request #443 from YOU54F/ci/win-runners
ci: add windows runners
2 parents 99d6f4b + f7d3a81 commit 6b525b4

19 files changed

+303
-108
lines changed

.github/workflows/test.yml

+12-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
1.21.x,
2626
1.22.x,
2727
]
28-
os: [ubuntu-latest, macos-12, macos-14]
28+
os: [ubuntu-latest, macos-12, macos-14, windows-latest]
2929
runs-on: ${{ matrix.os }}
3030
steps:
3131
- name: Checkout code
@@ -43,15 +43,26 @@ jobs:
4343
- name: Test
4444
if: matrix.os == 'ubuntu-latest'
4545
run: APP_BRANCH=${APP_REF:11} DOCKER_GATEWAY_HOST=172.17.0.1 DOCKER_HOST_HTTP="http://172.17.0.1" make
46+
- name: Set CGO_LDFLAGS / pact_ffi lib on PATH
47+
if: matrix.os == 'windows-latest'
48+
run: |
49+
"CGO_LDFLAGS=-L$env:TMP" >> $env:GITHUB_ENV
50+
"$env:TMP" >> $env:GITHUB_PATH
51+
- name: Skip Avro plugin & test (windows)
52+
if: matrix.os == 'windows-latest'
53+
run: |
54+
"SKIP_PLUGIN_AVRO=1" >> $env:GITHUB_ENV
4655
- name: Test (unit)
4756
if: matrix.os != 'ubuntu-latest'
4857
run: make test
4958
- name: Test (pact)
5059
if: matrix.os != 'ubuntu-latest'
5160
run: make pact_local
5261
- name: Install goveralls
62+
if: matrix.os != 'windows-latest'
5363
run: go install github.com/mattn/goveralls@latest
5464
- name: Send coverage
65+
if: matrix.os != 'windows-latest'
5566
run: goveralls -coverprofile=coverage.txt -service=github -parallel
5667
- uses: actions/upload-artifact@v4
5768
with:

Makefile

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ PLUGIN_PACT_AVRO_VERSION=0.0.5
1111

1212
GO_VERSION?=1.22
1313
ci:: docker deps clean bin test pact
14+
PACT_DOWNLOAD_DIR=/tmp
15+
ifeq ($(OS),Windows_NT)
16+
PACT_DOWNLOAD_DIR=$$TMP
17+
endif
1418

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

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

6969
download_plugins:
7070
@echo "--- 🐿 Installing plugins"; \
@@ -106,7 +106,7 @@ cli:
106106

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

111111
pact: clean install docker
112112
@echo "--- 🔨 Running Pact examples"

consumer/http_v4_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package consumer
33
import (
44
"fmt"
55
"os"
6+
"strings"
67
"testing"
78

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

5354
dir, _ := os.Getwd()
54-
path := fmt.Sprintf("%s/pact_plugin.proto", dir)
55+
path := fmt.Sprintf("%s/pact_plugin.proto", strings.ReplaceAll(dir, "\\", "/"))
5556

5657
err = p.AddInteraction().
5758
Given("some state").

examples/avro/avro_consumer_test.go

+33-30
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/http"
1010
"net/url"
1111
"os"
12+
"strings"
1213
"testing"
1314

1415
"github.com/pact-foundation/pact-go/v2/consumer"
@@ -21,45 +22,47 @@ import (
2122
var dir, _ = os.Getwd()
2223

2324
func TestAvroHTTP(t *testing.T) {
24-
mockProvider, err := consumer.NewV4Pact(consumer.MockHTTPProviderConfig{
25-
Consumer: "AvroConsumer",
26-
Provider: "AvroProvider",
27-
PactDir: filepath.ToSlash(fmt.Sprintf("%s/../pacts", dir)),
28-
})
29-
assert.NoError(t, err)
25+
if os.Getenv("SKIP_PLUGIN_AVRO") != "1" {
26+
mockProvider, err := consumer.NewV4Pact(consumer.MockHTTPProviderConfig{
27+
Consumer: "AvroConsumer",
28+
Provider: "AvroProvider",
29+
PactDir: filepath.ToSlash(fmt.Sprintf("%s/../pacts", dir)),
30+
})
31+
assert.NoError(t, err)
3032

31-
dir, _ := os.Getwd()
32-
path := fmt.Sprintf("%s/user.avsc", dir)
33+
dir, _ := os.Getwd()
34+
path := fmt.Sprintf("%s/user.avsc", strings.ReplaceAll(dir, "\\", "/"))
3335

34-
avroResponse := `{
36+
avroResponse := `{
3537
"pact:avro": "` + path + `",
3638
"pact:record-name": "User",
3739
"pact:content-type": "avro/binary",
3840
"id": "matching(number, 1)",
3941
"username": "notEmpty('matt')"
4042
}`
4143

42-
// Set up our expected interactions.
43-
err = mockProvider.
44-
AddInteraction().
45-
UponReceiving("A request to do get some Avro stuff").
46-
UsingPlugin(consumer.PluginConfig{
47-
Plugin: "avro",
48-
Version: "0.0.5",
49-
}).
50-
WithRequest("GET", "/avro").
51-
WillRespondWith(200, func(res *consumer.V4InteractionWithPluginResponseBuilder) {
52-
res.PluginContents("avro/binary", avroResponse)
53-
}).
54-
ExecuteTest(t, func(msc consumer.MockServerConfig) error {
55-
resp, err := callServiceHTTP(msc)
56-
57-
assert.Equal(t, int64(1), resp.ID)
58-
assert.Equal(t, "matt", resp.Username) // ??????!
59-
60-
return err
61-
})
62-
assert.NoError(t, err)
44+
// Set up our expected interactions.
45+
err = mockProvider.
46+
AddInteraction().
47+
UponReceiving("A request to do get some Avro stuff").
48+
UsingPlugin(consumer.PluginConfig{
49+
Plugin: "avro",
50+
Version: "0.0.5",
51+
}).
52+
WithRequest("GET", "/avro").
53+
WillRespondWith(200, func(res *consumer.V4InteractionWithPluginResponseBuilder) {
54+
res.PluginContents("avro/binary", avroResponse)
55+
}).
56+
ExecuteTest(t, func(msc consumer.MockServerConfig) error {
57+
resp, err := callServiceHTTP(msc)
58+
59+
assert.Equal(t, int64(1), resp.ID)
60+
assert.Equal(t, "matt", resp.Username) // ??????!
61+
62+
return err
63+
})
64+
assert.NoError(t, err)
65+
}
6366
}
6467

6568
func callServiceHTTP(msc consumer.MockServerConfig) (*User, error) {

examples/avro/avro_provider_test.go

+15-13
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,25 @@ var dir, _ = os.Getwd()
2121
var pactDir = fmt.Sprintf("%s/../pacts", dir)
2222

2323
func TestAvroHTTPProvider(t *testing.T) {
24-
httpPort, _ := utils.GetFreePort()
24+
if os.Getenv("SKIP_PLUGIN_AVRO") != "1" {
25+
httpPort, _ := utils.GetFreePort()
2526

26-
// Start provider API in the background
27-
go startHTTPProvider(httpPort)
27+
// Start provider API in the background
28+
go startHTTPProvider(httpPort)
2829

29-
verifier := provider.NewVerifier()
30+
verifier := provider.NewVerifier()
3031

31-
// Verify the Provider with local Pact Files
32-
err := verifier.VerifyProvider(t, provider.VerifyRequest{
33-
ProviderBaseURL: fmt.Sprintf("http://127.0.0.1:%d", httpPort),
34-
Provider: "AvroProvider",
35-
PactFiles: []string{
36-
filepath.ToSlash(fmt.Sprintf("%s/AvroConsumer-AvroProvider.json", pactDir)),
37-
},
38-
})
32+
// Verify the Provider with local Pact Files
33+
err := verifier.VerifyProvider(t, provider.VerifyRequest{
34+
ProviderBaseURL: fmt.Sprintf("http://127.0.0.1:%d", httpPort),
35+
Provider: "AvroProvider",
36+
PactFiles: []string{
37+
filepath.ToSlash(fmt.Sprintf("%s/AvroConsumer-AvroProvider.json", pactDir)),
38+
},
39+
})
3940

40-
assert.NoError(t, err)
41+
assert.NoError(t, err)
42+
}
4143
}
4244

4345
func startHTTPProvider(port int) {

examples/grpc/grpc_consumer_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"os"
1010
"path/filepath"
11+
"strings"
1112
"testing"
1213
"time"
1314

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

3132
dir, _ := os.Getwd()
32-
path := fmt.Sprintf("%s/routeguide/route_guide.proto", dir)
33+
path := fmt.Sprintf("%s/routeguide/route_guide.proto", strings.ReplaceAll(dir, "\\", "/"))
3334

3435
grpcInteraction := `{
3536
"pact:proto": "` + path + `",
@@ -102,7 +103,7 @@ func TestGetFeatureError(t *testing.T) {
102103
})
103104

104105
dir, _ := os.Getwd()
105-
path := fmt.Sprintf("%s/routeguide/route_guide.proto", dir)
106+
path := fmt.Sprintf("%s/routeguide/route_guide.proto", strings.ReplaceAll(dir, "\\", "/"))
106107

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

169170
dir, _ := os.Getwd()
170-
path := fmt.Sprintf("%s/routeguide/route_guide.proto", dir)
171+
path := fmt.Sprintf("%s/routeguide/route_guide.proto", strings.ReplaceAll(dir, "\\", "/"))
171172

172173
grpcInteraction := `{
173174
"pact:proto": "` + path + `",

examples/protobuf-message/protobuf_consumer_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"os"
99
"path/filepath"
10+
"strings"
1011
"testing"
1112

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

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

2829
protoMessage := `{
2930
"pact:proto": "` + path + `",

internal/native/c_types_unix.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build darwin || linux
2+
3+
package native
4+
5+
import "C"
6+
7+
type CUlong = C.ulong

internal/native/c_types_win.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build windows
2+
3+
package native
4+
5+
import "C"
6+
7+
type CUlong = C.ulonglong

internal/native/message_server.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func (m *Message) WithRequestBinaryContents(body []byte) *Message {
172172
defer free(cHeader)
173173

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

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

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

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

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

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

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

208208
return m
209209
}

internal/native/message_server_test.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"io"
1010
l "log"
1111
"os"
12+
"strings"
1213
"testing"
1314
"time"
1415

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

220221
dir, _ := os.Getwd()
221-
path := fmt.Sprintf("%s/pact_plugin.proto", dir)
222+
path := fmt.Sprintf("%s/pact_plugin.proto", strings.ReplaceAll(dir, "\\", "/"))
222223

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

278279
dir, _ := os.Getwd()
279-
path := fmt.Sprintf("%s/pact_plugin.proto", dir)
280+
path := fmt.Sprintf("%s/pact_plugin.proto", strings.ReplaceAll(dir, "\\", "/"))
280281

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

324325
dir, _ := os.Getwd()
325-
path := fmt.Sprintf("%s/pact_plugin.proto", dir)
326+
path := fmt.Sprintf("%s/pact_plugin.proto", strings.ReplaceAll(dir, "\\", "/"))
326327

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

365366
dir, _ := os.Getwd()
366-
path := fmt.Sprintf("%s/pact_plugin.proto", dir)
367+
path := fmt.Sprintf("%s/pact_plugin.proto", strings.ReplaceAll(dir, "\\", "/"))
367368

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

443444
dir, _ := os.Getwd()
444-
path := fmt.Sprintf("%s/pact_plugin.proto", dir)
445+
path := fmt.Sprintf("%s/pact_plugin.proto", strings.ReplaceAll(dir, "\\", "/"))
445446

446447
grpcInteraction := `{
447448
"pact:proto": "` + path + `",

internal/native/mock_server.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ func (i *Interaction) withHeaders(part interactionPart, valueOrMatcher map[strin
541541
value := stringFromInterface(header)
542542
cValue := C.CString(value)
543543

544-
C.pactffi_with_header_v2(i.handle, C.int(part), cName, C.ulong(0), cValue)
544+
C.pactffi_with_header_v2(i.handle, C.int(part), cName, CUlong(0), cValue)
545545

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

563-
C.pactffi_with_query_parameter_v2(i.handle, cName, C.ulong(idx), cValue)
563+
C.pactffi_with_query_parameter_v2(i.handle, cName, CUlong(idx), cValue)
564564

565565
free(cValue)
566566
}
@@ -616,7 +616,7 @@ func (i *Interaction) withBinaryBody(contentType string, body []byte, part inter
616616
cHeader := C.CString(contentType)
617617
defer free(cHeader)
618618

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

621621
return i
622622
}

0 commit comments

Comments
 (0)