-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
81 lines (66 loc) · 1.55 KB
/
client_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package book_test
import (
book "book-client"
"errors"
"fmt"
"github.com/pact-foundation/pact-go/dsl"
"github.com/stretchr/testify/suite"
"net/http"
"testing"
)
type ClientSuite struct {
suite.Suite
}
var pact *dsl.Pact
func TestClient(t *testing.T) {
suite.Run(t, new(ClientSuite))
}
func (s *ClientSuite) SetupSuite() {
pact = &dsl.Pact{
Consumer: "MarksBookClient",
Provider: "BookService",
PactDir: "./pacts",
}
}
func (s *ClientSuite) TearDownSuite() {
pact.Teardown()
}
func (s *ClientSuite) TestRetrievingBookThatDoesNotExist() {
pact.AddInteraction().
Given("There is not a book with ISBN 123456789").
UponReceiving("A GET request for book with ISBN 123456789").
WithRequest(
dsl.Request{
Method: http.MethodGet,
Path: dsl.String("/book/123-4567890123"),
Headers: dsl.MapMatcher{
"Accept": dsl.String("application/json"),
},
},
).
WillRespondWith(
dsl.Response{
Status: http.StatusNotFound,
Headers: dsl.MapMatcher{
"Content-Type": dsl.String("application/json"),
},
Body: dsl.Match(book.JsonError{}),
},
)
test := func() error {
c := book.NewClient(fmt.Sprintf("http://localhost:%d", pact.Server.Port))
_, err := c.GetBook("123-4567890123")
s.Error(err)
s.Equal(err.Error(), "No book with ISBN 123-4567890123")
if s.T().Failed() {
return errors.New("failed validating error response")
}
return nil
}
s.NoError(pact.Verify(test))
}
func (s *ClientSuite) TestRetrievingBookThatDoesExist() {
s.False(s.T().Failed())
}
func (s *ClientSuite) TestCreatingBook() {
}