Skip to content

Commit

Permalink
chore(docs): update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Jul 10, 2016
1 parent 6455c33 commit f4d1bc1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,34 +72,42 @@ running for long periods (e.g. on a CI server).*
### Consumer
1. Start the daemon with `./pact-go daemon`.
1. `cd <pact-go>/examples`.
1. `go run consumer.go`.
1. `go run -v consumer.go`.

Here is a simple example (`consumer_test.go`) you can run with `go test -v .`:

```go
import "github.com/pact-foundation/pact-go/dsl"
import ...
package somepackage

import (
"fmt"
"github.com/pact-foundation/pact-go/dsl"
"net/http"
"testing"
)

func TestLogin(t *testing.T) {

// Create Pact, connecting to local Daemon
// Ensure the port matches the daemon port!
pact := dsl.Pact{
Port: 6666,
Consumer: "My Consumer",
Provider: "My Provider",
Port: 6666,
Consumer: "MyConsumer",
Provider: "MyProvider",
}
// Shuts down Mock Service when done
defer pact.Teardown()

// Pass in your test case as a function to Verify()
var test = func() error {
_, err := http.Get("http://localhost:8000/")
_, err := http.Get(fmt.Sprintf("http://localhost:%d/login", pact.Server.Port))
return err
}

// Set up our interactions. Note we have multiple in this test case!
pact.
AddInteraction().
Given("User Matt exists"). // Provider State
Given("User Matt exists"). // Provider State
UponReceiving("A request to login"). // Test Case Name
WithRequest(dsl.Request{
Method: "GET",
Expand All @@ -118,6 +126,7 @@ func TestLogin(t *testing.T) {
// Write pact to file `<pact-go>/pacts/my_consumer-my_provider.json`
pact.WritePact()
}

```


Expand Down
4 changes: 2 additions & 2 deletions examples/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func main() {
// Create Pact connecting to local Daemon
pact := &dsl.Pact{
Port: 6666, // Ensure this port matches the daemon port!
Consumer: "My Consumer",
Provider: "My Provider",
Consumer: "MyConsumer",
Provider: "MyProvider",
}
defer pact.Teardown()

Expand Down

0 comments on commit f4d1bc1

Please sign in to comment.