Skip to content

Commit

Permalink
fix(test): add consumer test for #36
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Jun 26, 2017
1 parent e69da15 commit e1aaa4f
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions dsl/pact_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import (
"os"
"testing"

"bytes"

"github.com/pact-foundation/pact-go/types"
"github.com/pact-foundation/pact-go/utils"
)

var dir, _ = os.Getwd()
var pactDir = fmt.Sprintf("%s/../pacts", dir)
var logDir = fmt.Sprintf("%s/../log", dir)
var name = "Jean-Marie de La Beaujardière😀😍"

func TestPact_Integration(t *testing.T) {
// Enable when running E2E/integration tests before a release
Expand All @@ -36,11 +39,15 @@ func TestPact_Integration(t *testing.T) {

// Pass in test case
var test = func() error {
// Get request /foobar
_, err := http.Get(fmt.Sprintf("http://localhost:%d/foobar", consumerPact.Server.Port))
if err != nil {
t.Fatalf("Error sending request: %v", err)
}
_, err = http.Get(fmt.Sprintf("http://localhost:%d/bazbat", consumerPact.Server.Port))

// Post request /bazbat
bodyRequest := bytes.NewBufferString(fmt.Sprintf(`{"name": "%s"}`, name))
_, err = http.Post(fmt.Sprintf("http://localhost:%d/bazbat", consumerPact.Server.Port), "application/json", bodyRequest)
if err != nil {
t.Fatalf("Error sending request: %v", err)
}
Expand All @@ -61,11 +68,11 @@ func TestPact_Integration(t *testing.T) {
EachLike(
fmt.Sprintf(
`{
"name": "Jean-Marie de La Beaujardière😀😍",
"name": "%s",
"size": %s,
"colour": %s,
"tag": %s
}`, size, colour, tag),
}`, name, size, colour, tag),
1),
1))

Expand All @@ -89,8 +96,12 @@ func TestPact_Integration(t *testing.T) {
Given("Some state2").
UponReceiving("Some name for the test").
WithRequest(Request{
Method: "GET",
Method: "POST",
Path: "/bazbat",
Body: fmt.Sprintf(`
{
"name": "%s"
}`, name),
}).
WillRespondWith(Response{
Status: 200,
Expand Down Expand Up @@ -209,7 +220,7 @@ func setupProviderAPI() int {
[
[
{
"name": "Jean-Marie de La Baujardière😀😍",
"name": "%s",
"size": 10,
"colour": "red",
"tag": [
Expand All @@ -224,7 +235,7 @@ func setupProviderAPI() int {
]
}
]
]`)
]`, name)
})

go http.ListenAndServe(fmt.Sprintf(":%d", port), mux)
Expand Down

0 comments on commit e1aaa4f

Please sign in to comment.