Skip to content

Commit

Permalink
Merge branch 'master' into snyk-fix-5ef386de90cc3240ee6db1dfbc0b92a6
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows authored Aug 9, 2021
2 parents 0975c27 + 39746d2 commit f478020
Show file tree
Hide file tree
Showing 27 changed files with 206 additions and 183 deletions.
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,35 @@ Do this to generate your change history

## Versions

### v1.6.4 (09 August 2021)
* [936315b](https://github.com/pact-foundation/pact-go/commit/936315b) - chore: tidy up consumer version selectors (Matt Fellows, Mon Aug 9 17:14:57 2021 +1000)
* [01b8e81](https://github.com/pact-foundation/pact-go/commit/01b8e81) - fix: fixed linter errors in dsl/pact (antklim, Fri Jul 30 17:27:18 2021 +1000)
* [5a5ef03](https://github.com/pact-foundation/pact-go/commit/5a5ef03) - fix: fixed linter errors in client/service_manager (antklim, Fri Jul 30 17:17:37 2021 +1000)
* [72a05bf](https://github.com/pact-foundation/pact-go/commit/72a05bf) - fix: fixing linter errors in client/service_manager (antklim, Fri Jul 30 17:14:16 2021 +1000)
* [60ddda1](https://github.com/pact-foundation/pact-go/commit/60ddda1) - fix: fixed linter errors in dsl/client (antklim, Fri Jul 30 17:09:11 2021 +1000)
* [d88f9c3](https://github.com/pact-foundation/pact-go/commit/d88f9c3) - fix: fixing linter errors in dsl/client (antklim, Fri Jul 30 17:06:45 2021 +1000)
* [4f57f48](https://github.com/pact-foundation/pact-go/commit/4f57f48) - fix: fixing linter error in dsl/pact (antklim, Fri Jul 30 16:57:38 2021 +1000)
* [6bc61f4](https://github.com/pact-foundation/pact-go/commit/6bc61f4) - fix: fixing linter in dsl and client packages (antklim, Fri Jul 30 12:56:10 2021 +1000)
* [1ccc97e](https://github.com/pact-foundation/pact-go/commit/1ccc97e) - fix: fixed linter errors in test files (antklim, Fri Jul 30 12:09:44 2021 +1000)

### v1.6.3 (09 August 2021)
* [530d6ce](https://github.com/pact-foundation/pact-go/commit/530d6ce) - chore: tidy up consumer version selectors (Matt Fellows, Mon Aug 9 17:14:57 2021 +1000)
* [de0bb5e](https://github.com/pact-foundation/pact-go/commit/de0bb5e) - feat: support release and environment consumer version selectors (antklim, Thu Jul 29 17:57:40 2021 +1000)

### v1.5.3 (03 July 2021)
* [5903b70](https://github.com/pact-foundation/pact-go/commit/5903b70) - fix: handle verification response correctly (bbmokus, Fri Jul 2 16:49:11 2021 +0200)
* [d879a4b](https://github.com/pact-foundation/pact-go/commit/d879a4b) - fix(readme): update link to pact broker (Travis Dixon, Mon Jun 21 08:35:50 2021 +1000)
* [2c7a939](https://github.com/pact-foundation/pact-go/commit/2c7a939) - docs: clarify how the verification runs if both PactURLs and BrokerURL are provided (Matt Fellows, Wed Jun 16 11:16:31 2021 +1000)
* [65f4304](https://github.com/pact-foundation/pact-go/commit/65f4304) - Pass consumer version selectors in VerifyMessageProviderRaw (James Halsall, Tue Jun 15 09:50:46 2021 +0100)
* [629d508](https://github.com/pact-foundation/pact-go/commit/629d508) - docs: add note about roadmap/rust shared core (Matt Fellows, Sun May 30 12:18:41 2021 +1000)
* [a1d589a](https://github.com/pact-foundation/pact-go/commit/a1d589a) - chore: update slack links (Matt Fellows, Sat May 29 22:57:03 2021 +1000)
* [aa482a7](https://github.com/pact-foundation/pact-go/commit/aa482a7) - chore: add link to v3 beta (Matt Fellows, Sat May 29 22:55:59 2021 +1000)
* [bc10b4b](https://github.com/pact-foundation/pact-go/commit/bc10b4b) - fix: Dockerfile to reduce vulnerabilities (snyk-bot, Wed Mar 31 06:18:39 2021 +0000)
* [6d76336](https://github.com/pact-foundation/pact-go/commit/6d76336) - doc: small fix in golang README (Duke, Fri Mar 5 18:17:01 2021 -0300)
* [f0d0443](https://github.com/pact-foundation/pact-go/commit/f0d0443) - refactor: remove unnecessary return (g1stavo, Fri Feb 26 09:41:59 2021 -0300)
* [8cde90c](https://github.com/pact-foundation/pact-go/commit/8cde90c) - docs: omit explicit returns (g1stavo, Fri Feb 26 00:29:10 2021 -0300)
* [d1484a4](https://github.com/pact-foundation/pact-go/commit/d1484a4) - docs: add missing return (g1stavo, Fri Feb 26 00:18:43 2021 -0300)

### v1.5.2 (25 March 2021)
* [bae7fd8](https://github.com/pact-foundation/pact-go/commit/bae7fd8) - chore: demonstrate use of loglevel and log dir for TLS provider (Matt Fellows, Thu Mar 25 13:19:45 2021 +1100)
* [8ed3655](https://github.com/pact-foundation/pact-go/commit/8ed3655) - chore: add log level to verifier CLI (Matt Fellows, Thu Mar 25 13:15:44 2021 +1100)
Expand Down
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Read [Getting started with Pact] for more information for beginners.
- [Installation](#installation)
- [Go get](#go-get)
- [Installation on \*nix](#installation-on-\nix)
- [V3 Beta](#v3-beta)
- [Using Pact](#using-pact)
- [HTTP API Testing](#http-api-testing)
- [Consumer Side Testing](#consumer-side-testing)
Expand Down Expand Up @@ -99,6 +100,7 @@ Read [Getting started with Pact] for more information for beginners.

| Version | Stable | [Spec] Compatibility | Install |
|---------|--------|----------------------|--------------------|
| 2.x.x | Beta | 2, 3 | See [v2.x.x] |
| 1.0.x | Yes | 2, 3\* | See [installation] |
| 0.x.x | Yes | Up to v2 | 0.x.x [stable] |

Expand Down Expand Up @@ -137,6 +139,10 @@ Test the installation:
pact help
```

## V3 Beta

If you are interested in testing out the new new beta package that supports all of the V3 [spec], and moves to a rust shared core, please head to [v2.x.x] and also let us know on [slack].

## Using Pact

Pact supports [synchronous request-response style HTTP interactions](#http-api-testing) and has experimental support for [asynchronous interactions](#asynchronous-api-testing) with JSON-formatted payloads.
Expand Down Expand Up @@ -175,7 +181,7 @@ func TestConsumer(t *testing.T) {
u := fmt.Sprintf("http://localhost:%d/foobar", pact.Server.Port)
req, err := http.NewRequest("GET", u, strings.NewReader(`{"name":"billy"}`))
if err != nil {
return err
return
}

// NOTE: by default, request bodies are expected to be sent with a Content-Type
Expand All @@ -184,9 +190,8 @@ func TestConsumer(t *testing.T) {
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer 1234")

if _, err = http.DefaultClient.Do(req); err != nil {
return err
}
_, err = http.DefaultClient.Do(req)
return
}

// Set up our expected interactions.
Expand Down Expand Up @@ -245,7 +250,7 @@ Here is the Provider test process broker down:
}
```

2) Verify provider API
2. Verify provider API

You can now tell Pact to read in your Pact files and verify that your API will
satisfy the requirements of each of your known consumers:
Expand Down Expand Up @@ -282,7 +287,7 @@ and giving you granular test reporting. If you don't like this behaviour, you ma
Note that `PactURLs` may be a list of local pact files or remote based
urls (e.g. from a
[Pact Broker](http://docs.pact.io/documentation/sharings_pacts.html)).
[Pact Broker](https://docs.pact.io/pact_broker)).
#### Provider Verification
Expand Down Expand Up @@ -918,8 +923,9 @@ Additional documentation can be found at the main [Pact website](https://pact.io

## Roadmap

The [roadmap](https://docs.pact.io/roadmap/) for Pact and Pact Go is outlined on our main website.
Detail on the native Go implementation can be found [here](https://github.com/pact-foundation/pact-go/wiki/Native-implementation-roadmap).
The current focus is on moving to the Rust shared core, the project can be followed [here](https://github.com/pact-foundation/pact-go/projects/2).

The general [roadmap](https://docs.pact.io/roadmap/) for Pact is available on the Pact website.

## Contributing

Expand All @@ -931,7 +937,7 @@ See [CONTRIBUTING](https://github.com/pact-foundation/pact-go/edit/master/CONTRI
[troubleshooting]: https://github.com/pact-foundation/pact-go/wiki/Troubleshooting
[getting started with pact]: http://dius.com.au/2016/02/03/microservices-pact/
[pact website]: https://docs.pact.io/
[slack channel]: https://gophers.slack.com/messages/pact/
[slack channel]: https://pact-foundation.slack.com
[@pact_up]: https://twitter.com/pact_up
[pact specification v2]: https://github.com/pact-foundation/pact-specification/tree/version-2
[pact specification v3]: https://github.com/pact-foundation/pact-specification/tree/version-3
Expand All @@ -943,3 +949,5 @@ See [CONTRIBUTING](https://github.com/pact-foundation/pact-go/edit/master/CONTRI
[hosted broker]: https://pact.dius.com.au
[can-i-deploy tool]: https://docs.pact.io/can_i_deploy
[Pactflow]: https://pactflow.io
[v2.x.x]: https://github.com/pact-foundation/pact-go/tree/2.x.x
[slack]: https://slack.pact.io
23 changes: 9 additions & 14 deletions client/service_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,22 @@ func (s *ServiceManager) Setup() {
// addServiceMonitor watches a channel to add services into operation.
func (s *ServiceManager) addServiceMonitor() {
log.Println("[DEBUG] starting service creation monitor")
for {
select {
case p := <-s.commandCreatedChan:
if p != nil && p.Process != nil {
s.processMap.Set(p.Process.Pid, p)
}
for p := range s.commandCreatedChan {
if p != nil && p.Process != nil {
s.processMap.Set(p.Process.Pid, p)
}
}
}

// removeServiceMonitor watches a channel to remove services from operation.
func (s *ServiceManager) removeServiceMonitor() {
log.Println("[DEBUG] starting service removal monitor")
var p *exec.Cmd
for {
select {
case p = <-s.commandCompleteChan:
if p != nil && p.Process != nil {
p.Process.Signal(os.Interrupt)
s.processMap.Delete(p.Process.Pid)
for p := range s.commandCompleteChan {
if p != nil && p.Process != nil {
if err := p.Process.Signal(os.Interrupt); err != nil {
log.Println("[ERROR] service removal monitor failed to process signal:", err)
}
s.processMap.Delete(p.Process.Pid)
}
}
}
Expand Down Expand Up @@ -161,7 +156,7 @@ type processMap struct {
func (pm *processMap) Get(k int) *exec.Cmd {
pm.RLock()
defer pm.RUnlock()
v, _ := pm.processes[k]
v := pm.processes[k]
return v
}

Expand Down
25 changes: 7 additions & 18 deletions client/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var channelTimeout = 50 * time.Millisecond

func createServiceManager() *ServiceManager {
cs := []string{"-test.run=TestHelperProcess", "--", os.Args[0]}
env := []string{"GO_WANT_HELPER_PROCESS=1", fmt.Sprintf("GO_WANT_HELPER_PROCESS_TO_SUCCEED=true")}
env := []string{"GO_WANT_HELPER_PROCESS=1", "GO_WANT_HELPER_PROCESS_TO_SUCCEED=true"}
mgr := &ServiceManager{
Cmd: os.Args[0],
Args: cs,
Expand All @@ -24,9 +24,7 @@ func createServiceManager() *ServiceManager {
}

func TestServiceManager(t *testing.T) {
var manager interface{}
manager = new(ServiceManager)

var manager interface{} = new(ServiceManager)
if _, ok := manager.(*ServiceManager); !ok {
t.Fatalf("Must be a ServiceManager")
}
Expand All @@ -47,7 +45,7 @@ func TestServiceManager_Setup(t *testing.T) {
func TestServiceManager_removeServiceMonitor(t *testing.T) {
mgr := createServiceManager()
cmd := fakeExecCommand("", true, "")
cmd.Start()
cmd.Start() // nolint:errcheck
mgr.processMap.processes = map[int]*exec.Cmd{
cmd.Process.Pid: cmd,
}
Expand Down Expand Up @@ -75,7 +73,7 @@ func TestServiceManager_removeServiceMonitor(t *testing.T) {
func TestServiceManager_addServiceMonitor(t *testing.T) {
mgr := createServiceManager()
cmd := fakeExecCommand("", true, "")
cmd.Start()
cmd.Start() // nolint:errcheck
mgr.commandCreatedChan <- cmd
var timeout = time.After(channelTimeout)

Expand Down Expand Up @@ -128,12 +126,12 @@ func TestServiceManager_addServiceMonitorWithDeadJob(t *testing.T) {
func TestServiceManager_Stop(t *testing.T) {
mgr := createServiceManager()
cmd := fakeExecCommand("", true, "")
cmd.Start()
cmd.Start() // nolint:errcheck
mgr.processMap.processes = map[int]*exec.Cmd{
cmd.Process.Pid: cmd,
}

mgr.Stop(cmd.Process.Pid)
mgr.Stop(cmd.Process.Pid) // nolint:errcheck
var timeout = time.After(channelTimeout)
for {
mgr.processMap.Lock()
Expand All @@ -157,7 +155,7 @@ func TestServiceManager_Stop(t *testing.T) {
func TestServiceManager_List(t *testing.T) {
mgr := createServiceManager()
cmd := fakeExecCommand("", true, "")
cmd.Start()
cmd.Start() // nolint:errcheck
processes := map[int]*exec.Cmd{
cmd.Process.Pid: cmd,
}
Expand Down Expand Up @@ -196,15 +194,6 @@ func TestServiceManager_Start(t *testing.T) {
}
}

// Adapted from http://npf.io/2015/06/testing-exec-command/
var fakeExecSuccessCommand = func() *exec.Cmd {
return fakeExecCommand("", true, "")
}

var fakeExecFailCommand = func() *exec.Cmd {
return fakeExecCommand("", false, "")
}

func fakeExecCommand(command string, success bool, args ...string) *exec.Cmd {
cs := []string{"-test.run=TestHelperProcess", "--", command}
cs = append(cs, args...)
Expand Down
2 changes: 1 addition & 1 deletion command/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra"
)

var version = "v1.5.2"
var version = "v1.6.4"
var cliToolsVersion = "1.82.3"
var versionCmd = &cobra.Command{
Use: "version",
Expand Down
4 changes: 2 additions & 2 deletions dsl/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func setupMockBroker(auth bool) *httptest.Server {

w.Header().Set("WWW-Authenticate", `Basic realm="Broker Authentication Required"`)
w.WriteHeader(401)
w.Write([]byte("401 Unauthorized\n"))
w.Write([]byte("401 Unauthorized\n")) // nolint:errcheck
})
}
} else {
Expand Down Expand Up @@ -67,7 +67,7 @@ func setupMockBroker(auth bool) *httptest.Server {
mux.Handle("/pacts/provider/broken/latest/dev", authFunc(func(w http.ResponseWriter, req *http.Request) {
log.Println("[DEBUG] broker broker response")
w.WriteHeader(500)
w.Write([]byte("500 Server Error\n"))
w.Write([]byte("500 Server Error\n")) // nolint:errcheck
}))

// Find 'bobby' consumers for tag 'dev'
Expand Down
20 changes: 12 additions & 8 deletions dsl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ func (p *PactClient) StartServer(args []string, port int) *types.MockServer {
svc := p.pactMockSvcManager.NewService(args)
cmd := svc.Start()

waitForPort(port, p.getNetworkInterface(), p.Address, p.TimeoutDuration,
err := waitForPort(port, p.getNetworkInterface(), p.Address, p.TimeoutDuration,
fmt.Sprintf(`Timed out waiting for Mock Server to start on port %d - are you sure it's running?`, port))
if err != nil {
log.Println("[ERROR] client: failed to wait for Mock Server:", err)
}

return &types.MockServer{
Pid: cmd.Process.Pid,
Expand Down Expand Up @@ -137,7 +140,9 @@ func (p *PactClient) RemoveAllServers(server *types.MockServer) []*types.MockSer

for _, s := range p.verificationSvcManager.List() {
if s != nil {
p.pactMockSvcManager.Stop(s.Process.Pid)
if _, err := p.pactMockSvcManager.Stop(s.Process.Pid); err != nil {
log.Println("[ERROR] client: stop server failed:", err)
}
}
}
return nil
Expand Down Expand Up @@ -195,8 +200,8 @@ func (p *PactClient) VerifyProvider(request types.VerifyRequest) ([]types.Provid
// Each pact is verified by line, and the results (as JSON) sent to stdout.
// See https://github.com/pact-foundation/pact-go/issues/88#issuecomment-404686337
stdOutScanner := bufio.NewScanner(stdOutPipe)
wg.Add(1)
go func() {
wg.Add(1)
defer wg.Done()
stdOutBuf := make([]byte, bufio.MaxScanTokenSize)
stdOutScanner.Buffer(stdOutBuf, 64*1024*1024)
Expand All @@ -208,13 +213,12 @@ func (p *PactClient) VerifyProvider(request types.VerifyRequest) ([]types.Provid

// Scrape errors
stdErrScanner := bufio.NewScanner(stdErrPipe)
wg.Add(1)
go func() {
wg.Add(1)
defer wg.Done()
for stdErrScanner.Scan() {
stdErr.WriteString(fmt.Sprintf("%s\n", stdErrScanner.Text()))
}

}()

err = cmd.Start()
Expand All @@ -226,7 +230,6 @@ func (p *PactClient) VerifyProvider(request types.VerifyRequest) ([]types.Provid
err = cmd.Wait()
wg.Wait()

var verification types.ProviderVerifierResponse
for _, v := range verifications {
v = strings.TrimSpace(v)

Expand All @@ -235,6 +238,7 @@ func (p *PactClient) VerifyProvider(request types.VerifyRequest) ([]types.Provid
// logging to stdout breaks the JSON response
// https://github.com/pact-foundation/pact-ruby/commit/06fa61581512ba5570c315d089f2c0fc23c8cb11
if v != "" && strings.Index(v, "INFO") != 0 {
var verification types.ProviderVerifierResponse
dErr := json.Unmarshal([]byte(v), &verification)

response = append(response, verification)
Expand Down Expand Up @@ -429,13 +433,13 @@ var waitForPort = func(port int, network string, address string, timeoutDuration
func sanitiseRubyResponse(response string) string {
log.Println("[TRACE] response from Ruby process pre-sanitisation:", response)

r := regexp.MustCompile("(?m)^\\s*#.*$")
r := regexp.MustCompile(`(?m)^\s*#.*$`)
s := r.ReplaceAllString(response, "")

r = regexp.MustCompile("(?m).*bundle exec rake pact:verify.*$")
s = r.ReplaceAllString(s, "")

r = regexp.MustCompile("\\n+")
r = regexp.MustCompile(`\n+`)
s = r.ReplaceAllString(s, "\n")

return s
Expand Down
Loading

0 comments on commit f478020

Please sign in to comment.