From 81d0c46245efc7359be3c827655ab013c2045343 Mon Sep 17 00:00:00 2001 From: Matt Fellows Date: Sat, 5 May 2018 12:17:46 +1000 Subject: [PATCH] examples(message): fix message provider example --- dsl/pact.go | 2 ++ .../provider/message_pact_provider_test.go | 24 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/dsl/pact.go b/dsl/pact.go index 3ebf1cb50..46998ad3c 100644 --- a/dsl/pact.go +++ b/dsl/pact.go @@ -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 } @@ -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") } }) } diff --git a/examples/messages/provider/message_pact_provider_test.go b/examples/messages/provider/message_pact_provider_test.go index 8cc7825eb..8e82609f1 100644 --- a/examples/messages/provider/message_pact_provider_test.go +++ b/examples/messages/provider/message_pact_provider_test.go @@ -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 @@ -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. @@ -46,7 +58,7 @@ func createPact() dsl.Pact { Consumer: "PactGoMessageConsumer", Provider: "PactGoMessageProvider", LogDir: logDir, - LogLevel: "DEBUG", + LogLevel: "WARN", PactFileWriteMode: "update", } }