Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ jobs:
fetch-depth: 0
fetch-tags: true
- uses: "actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491" # v5.0.0
with:
go-version-file: go.mod
- name: test
run: |
make lint
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*.out
.idea

.gocache/

pacttesting/target
pacttesting/logs
pact/
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Using golangci-lint@v1.56.2
# Using golangci-lint@v1.64.8
run:
timeout: 5m
tests: true
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.DEFAULT_GOAL := default

GOLANGCI_VERSION := 1.56.2
GOLANGCI_VERSION := 1.64.8

platform := $(shell uname)
pact_version := "1.88.51"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/avast/retry-go/v4 v4.5.1
github.com/pact-foundation/pact-go v1.8.0
github.com/pact-foundation/pact-go v1.10.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/viper v1.18.2
github.com/stretchr/testify v1.8.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/pact-foundation/pact-go v1.8.0 h1:On9JjJZrzwqmT2UICedWqLpcAtqVyd/ktt0SVJFTdL4=
github.com/pact-foundation/pact-go v1.8.0/go.mod h1:YLt/uSQGo9x5ZUjynLzNy3IiORlA4BtbR9p2yxgD2as=
github.com/pact-foundation/pact-go v1.10.0 h1:LE954RwmeV0rSm21umyPGGCvzHkEhglowkNGyuMwNGM=
github.com/pact-foundation/pact-go v1.10.0/go.mod h1:YLt/uSQGo9x5ZUjynLzNy3IiORlA4BtbR9p2yxgD2as=
github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI=
github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
20 changes: 14 additions & 6 deletions pacttesting/message_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ import (

const providerHTTPScheme = "http://"

const (
verificationDirMode = 0o744
verificationFileMode = 0o600
messageReadHeaderTimeout = 3 * time.Second
messageWaitForPortTimeout = 5 * time.Second
waitForPortPollInterval = 50 * time.Millisecond
)

func VerifyProviderMessagingPacts(params PactProviderTestParams, messageProducers dsl.MessageHandlers) {
buildPactClientOnce()

Expand Down Expand Up @@ -81,9 +89,9 @@ func VerifyProviderMessagingPacts(params PactProviderTestParams, messageProducer
err == nil && allTestsSucceeded,
version)
verificationDir := filepath.Join(topLevelDir, "build", "pact-verifications")
_ = os.MkdirAll(verificationDir+"/", 0o744)
_ = os.MkdirAll(verificationDir+"/", verificationDirMode)
verificationFile := filepath.Join(verificationDir, filename)
if err := os.WriteFile(verificationFile, []byte(verificationJSON), 0o600); err != nil {
if err := os.WriteFile(verificationFile, []byte(verificationJSON), verificationFileMode); err != nil {
t.Fatal(err)
}
outputJSON, err := json.Marshal(response)
Expand All @@ -92,7 +100,7 @@ func VerifyProviderMessagingPacts(params PactProviderTestParams, messageProducer
}

outFile := filepath.Join(topLevelDir, "build/pact-verifications/", "output-"+filename)
if err := os.WriteFile(outFile, outputJSON, 0o600); err != nil {
if err := os.WriteFile(outFile, outputJSON, verificationFileMode); err != nil {
t.Fatal(err)
}
})
Expand Down Expand Up @@ -213,13 +221,13 @@ func VerifyMessageProviderRaw(

server := http.Server{
Handler: mux,
ReadHeaderTimeout: 3 * time.Second,
ReadHeaderTimeout: messageReadHeaderTimeout,
}

log.Printf("[DEBUG] API handler starting: port %d (%s)", port, ln.Addr())
go func() { _ = server.Serve(ln) }()

portErr := waitForPort(port, "tcp", getBindAddress(), 5*time.Second,
portErr := waitForPort(port, "tcp", getBindAddress(), messageWaitForPortTimeout,
fmt.Sprintf(`Timed out waiting for Daemon on port %d - are you sure it's running?`, port))

if portErr != nil {
Expand All @@ -244,7 +252,7 @@ func waitForPort(port int, network string, address string, timeoutDuration time.
case <-timeout:
log.Printf("[ERROR] Expected server to start < %s. %s", timeoutDuration, message)
return fmt.Errorf("expected server to start < %s. %s", timeoutDuration, message)
case <-time.After(50 * time.Millisecond):
case <-time.After(waitForPortPollInterval):
_, err := net.Dial(network, fmt.Sprintf("%s:%d", address, port))
if err == nil {
return nil
Expand Down
13 changes: 10 additions & 3 deletions pacttesting/mock_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ type MockServer struct {
Running bool `json:"-"`
}

const (
pidDirMode = 0o755
pidFileMode = 0o600
stopRetryAttempts = 25
stopRetryDelay = 200 * time.Millisecond
)

// call sends a message to the Pact service
func (m *MockServer) call(method string, url string, content *string) error {
client := &http.Client{}
Expand Down Expand Up @@ -90,11 +97,11 @@ func (m *MockServer) writePidFile() {
return
}
dir, _ := os.Getwd()
_ = os.MkdirAll(filepath.FromSlash(filepath.Join(dir, "pact", "pids")), os.ModePerm)
_ = os.MkdirAll(filepath.FromSlash(filepath.Join(dir, "pact", "pids")), pidDirMode)
file := filepath.FromSlash(
fmt.Sprintf("%s/pact-%s-%s.json", filepath.Join(dir, "pact", "pids"), m.Provider, m.Consumer),
)
err = os.WriteFile(file, bytes, os.ModePerm)
err = os.WriteFile(file, bytes, pidFileMode)
if err != nil {
log.WithError(err).Errorf("unable to store mock server details")
return
Expand All @@ -120,7 +127,7 @@ func (m *MockServer) Stop() error {
return errors.New("server process is still alive")
}
return nil
}, retry.Attempts(25), retry.Delay(200*time.Millisecond), retry.DelayType(retry.FixedDelay)); err != nil {
}, retry.Attempts(stopRetryAttempts), retry.Delay(stopRetryDelay), retry.DelayType(retry.FixedDelay)); err != nil {
err = p.Kill()
if err != nil {
return fmt.Errorf("failed to kill process: %w", err)
Expand Down
4 changes: 3 additions & 1 deletion pacttesting/pact_file_split.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

type PactRequestMatchingFilter = func(map[string]interface{})

const splitPactFileMode = 0o644

// SplitPactBulkFile reads bulk PACT files, splits it into smaller ones
// and writes output to destination directory
func SplitPactBulkFile(bulkFilePath string, outputDirPath string, requestFilters ...PactRequestMatchingFilter) error {
Expand Down Expand Up @@ -51,7 +53,7 @@ func SplitPactBulkFile(bulkFilePath string, outputDirPath string, requestFilters

description := sanitize(tc.Interactions[0].Description)
tcFilePath := filepath.Join(outputDirPath, description+".json")
if writeErr := os.WriteFile(tcFilePath, json, os.ModePerm); writeErr != nil {
if writeErr := os.WriteFile(tcFilePath, json, splitPactFileMode); writeErr != nil {
return fmt.Errorf("couldn't write test case to file - interaction idx: %d , "+
"output file path: %s, err: %w", idx, tcFilePath, writeErr)
}
Expand Down
2 changes: 1 addition & 1 deletion pacttesting/pact_testing_integration_stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (s *pactTestingStage) the_service_gets_preassigned() *pactTestingStage {
func (s *pactTestingStage) the_service_has_a_preassigned_port() *pactTestingStage {
assert.NotEqual(s.t, "", viper.GetString("testservice-pre"))
assert.NotNil(s.t, pactServers["testservice-prego-pact-testing"])
assert.Greater(s.t, pactServers["testservice-prego-pact-testing"].Port, 0)
assert.Positive(s.t, pactServers["testservice-prego-pact-testing"].Port)
return s
}

Expand Down
25 changes: 17 additions & 8 deletions pacttesting/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ type pactName struct {
Name string `json:"name"`
}

const (
defaultRetryAttempts = 150000
defaultRetryDelay = 200 * time.Millisecond
mockServerHealthAttempts = 100
mockServerHealthDelay = 100 * time.Millisecond
providerVerificationDirMode = 0o744
providerVerificationFileMode = 0o600
)

//nolint:gochecknoglobals // fixing is a breaking API change
var (
pathOnce sync.Once
Expand All @@ -44,8 +53,8 @@ var (

func defaultRetryOptions() []retry.Option {
return []retry.Option{
retry.Attempts(150000),
retry.Delay(200 * time.Millisecond),
retry.Attempts(defaultRetryAttempts),
retry.Delay(defaultRetryDelay),
retry.DelayType(retry.FixedDelay),
}
}
Expand Down Expand Up @@ -163,7 +172,7 @@ func setBinPath() {
func buildPactClientOnce() {
once.Do(func() {
setBinPath()
pactClient = dsl.NewClient()
pactClient = dsl.NewClient("")
})
}

Expand Down Expand Up @@ -378,7 +387,7 @@ func EnsurePactRunning(provider, consumer string) string {
return fmt.Errorf("calling mock server: %w", retry.Unrecoverable(err))
}
return err
}, retry.DelayType(retry.FixedDelay), retry.Delay(100*time.Millisecond), retry.Attempts(100))
}, retry.DelayType(retry.FixedDelay), retry.Delay(mockServerHealthDelay), retry.Attempts(mockServerHealthAttempts))
if err != nil {
log.
WithError(err).
Expand Down Expand Up @@ -414,7 +423,7 @@ func RunIntegrationTest(t *testing.T, pactFilePaths []Pact, testFunc func(), ret
if err := retry.Do(verify, retryOptions...); err != nil {
log.Error("Pact verification failed!!" +
"For more info on the error check the logs/pact*.log files, they are quite detailed")
t.Errorf(err.Error())
t.Error(err)
}
})
}
Expand Down Expand Up @@ -546,9 +555,9 @@ func VerifyProviderPacts(params PactProviderTestParams) {
allTestsSucceeded,
version)
verificationDir := filepath.Join(topLevelDir, "build", "pact-verifications")
_ = os.MkdirAll(verificationDir+"/", 0o744)
_ = os.MkdirAll(verificationDir+"/", providerVerificationDirMode)
verificationFile := filepath.Join(verificationDir, filename)
if err := os.WriteFile(verificationFile, []byte(verificationJSON), 0o600); err != nil {
if err := os.WriteFile(verificationFile, []byte(verificationJSON), providerVerificationFileMode); err != nil {
t.Fatal(err)
}
outputJSON, err := json.Marshal(response)
Expand All @@ -557,7 +566,7 @@ func VerifyProviderPacts(params PactProviderTestParams) {
}

outFile := filepath.Join(topLevelDir, "build/pact-verifications/", "output-"+filename)
if err := os.WriteFile(outFile, outputJSON, 0o600); err != nil {
if err := os.WriteFile(outFile, outputJSON, providerVerificationFileMode); err != nil {
t.Fatal(err)
}
})
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions vendor/github.com/pact-foundation/pact-go/dsl/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion vendor/github.com/pact-foundation/pact-go/dsl/pact.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion vendor/github.com/pact-foundation/pact-go/dsl/publish.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading