Skip to content

Commit

Permalink
examples(message): fix message provider example
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed May 5, 2018
1 parent ad7454e commit 81d0c46
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions dsl/pact.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ func (p *Pact) VerifyMessageProvider(t *testing.T, request types.VerifyMessageRe
f, messageFound := handlers[message.Description]

if !messageFound {
log.Printf("[ERROR] message handler not found for message description: %v", message.Description)
w.WriteHeader(http.StatusNotFound)
return
}
Expand Down Expand Up @@ -415,6 +416,7 @@ func (p *Pact) VerifyMessageProvider(t *testing.T, request types.VerifyMessageRe
st.Log(example.FullDescription)
if example.Status != "passed" {
st.Errorf("%s\n", example.Exception.Message)
st.Error("Check to ensure that all message expectations have corresponding message handlers")
}
})
}
Expand Down
24 changes: 18 additions & 6 deletions examples/messages/provider/message_pact_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,23 @@ func TestMessageProvider_Success(t *testing.T) {
// Map test descriptions to message producer (handlers)
// TODO: convert these all to types to ease readability
functionMappings := dsl.MessageProviders{
"a test message": func(m dsl.Message) (interface{}, error) {
"some test case": func(m dsl.Message) (interface{}, error) {
fmt.Println("Calling 'text' function that would produce a message")
res := map[string]interface{}{
"content": map[string]string{
"text": "Hello world!!",
"content": map[string]interface{}{
"access": []map[string]string{
{
"role": "admin",
},
{
"role": "admin",
},
{
"role": "admin",
},
},
"id": 27,
"name": "Baz",
},
}
return res, nil
Expand All @@ -30,13 +42,13 @@ func TestMessageProvider_Success(t *testing.T) {

// Verify the Provider with local Pact Files
pact.VerifyMessageProvider(t, types.VerifyMessageRequest{
PactURLs: []string{filepath.ToSlash(fmt.Sprintf("%s/message-pact.json", pactDir))},
PactURLs: []string{filepath.ToSlash(fmt.Sprintf("%s/pactgomessageconsumer-pactgomessageprovider.json", pactDir))},
}, functionMappings)
}

// Configuration / Test Data
var dir, _ = os.Getwd()
var pactDir = fmt.Sprintf("%s/../pacts", dir)
var pactDir = fmt.Sprintf("%s/../../pacts", dir)
var logDir = fmt.Sprintf("%s/log", dir)

// Setup the Pact client.
Expand All @@ -46,7 +58,7 @@ func createPact() dsl.Pact {
Consumer: "PactGoMessageConsumer",
Provider: "PactGoMessageProvider",
LogDir: logDir,
LogLevel: "DEBUG",
LogLevel: "WARN",
PactFileWriteMode: "update",
}
}

0 comments on commit 81d0c46

Please sign in to comment.