From 0baf1cb869b469a21ccced9db5181375e0220c0f Mon Sep 17 00:00:00 2001 From: Ronan Barrett Date: Thu, 4 Apr 2019 15:43:54 +0200 Subject: [PATCH 1/4] fix CB lib name --- cloudbuild.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 0162951..b2a51a1 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -4,4 +4,4 @@ steps: - name: 'gcr.io/cloud-builders/docker' args: ['build', '-t', '${_LIBRARY_NAME}', '.', '--cache-from', 'eu.gcr.io/$PROJECT_ID/${_LIBRARY_NAME}'] substitutions: - _LIBRARY_NAME: flames-library-mockserver-client + _LIBRARY_NAME: mockserver-client-go From 4b955c3d4d21cc4efe4f89d932a466139b555c7f Mon Sep 17 00:00:00 2001 From: ronanbarrett Date: Thu, 4 Apr 2019 15:58:49 +0200 Subject: [PATCH 2/4] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c75d8a9..04d4b87 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Expectation Defaults: * unlimited calls will respond to a match * calls are not delayed * status of matched calls is 200 OK +* body of matched calls is empty Verification Defaults: * matched request occurs once i.e. at 1 least call and at most 1 call From 24b40721ede88319dd84a164b7637afee1bd5025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sofia=20Fr=C3=B6man?= Date: Tue, 9 Apr 2019 16:37:57 +0200 Subject: [PATCH 3/4] Allow for mock server to verify that a call was done at least and/or at most 0 times. Fix test. --- pkg/mockclient/expectations.go | 8 ++++---- pkg/mockclient/verifications.go | 12 ++++++++---- pkg/mockclient/verifications_test.go | 4 ++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/pkg/mockclient/expectations.go b/pkg/mockclient/expectations.go index e192450..ebfa764 100644 --- a/pkg/mockclient/expectations.go +++ b/pkg/mockclient/expectations.go @@ -37,8 +37,8 @@ type ResponseBody struct { // Times defines how many times the MockServer will serve a given request in expectation mode whilst // in verification mode defines the expected number of calls type Times struct { - AtLeast int `json:"atLeast,omitempty"` // valid for verifications only - AtMost int `json:"atMost,omitempty"` // valid for verifications only + AtLeast *int `json:"atLeast,omitempty"` // valid for verifications only + AtMost *int `json:"atMost,omitempty"` // valid for verifications only RemainingTimes int `json:"remainingTimes,omitempty"` // valid for expectations only Unlimited *bool `json:"unlimited,omitempty"` // valid for expectations only } @@ -197,6 +197,6 @@ func ThenResponseDelay(delay time.Duration) ExpectationOption { } func newBool(value bool) *bool { - b := value - return &b + b := value + return &b } diff --git a/pkg/mockclient/verifications.go b/pkg/mockclient/verifications.go index 8abf190..c46bf7f 100644 --- a/pkg/mockclient/verifications.go +++ b/pkg/mockclient/verifications.go @@ -13,8 +13,8 @@ func CreateVerification(opts ...ExpectationOption) *Expectation { Path: "/(.*)", }, Times: &Times{ - AtLeast: 1, - AtMost: 1, + AtLeast: integerPointer(1), + AtMost: integerPointer(1), }, } // Append all options that are set (discard defaults) @@ -28,7 +28,7 @@ func CreateVerification(opts ...ExpectationOption) *Expectation { // ThenAtLeastCalls creates a verification that a matching call was received at least x times by MockServer func ThenAtLeastCalls(times int) ExpectationOption { return func(v *Expectation) *Expectation { - v.Times.AtLeast = times + v.Times.AtLeast = integerPointer(times) return v } } @@ -36,7 +36,7 @@ func ThenAtLeastCalls(times int) ExpectationOption { // ThenAtMostCalls creates a verification that a matching call was received at most x times by MockServer func ThenAtMostCalls(times int) ExpectationOption { return func(v *Expectation) *Expectation { - v.Times.AtMost = times + v.Times.AtMost = integerPointer(times) return v } } @@ -63,3 +63,7 @@ func VerifyPath(path string) VerificationOption { } } */ + +func integerPointer(i int) *int { + return &i +} diff --git a/pkg/mockclient/verifications_test.go b/pkg/mockclient/verifications_test.go index 1ea823b..5d59faa 100644 --- a/pkg/mockclient/verifications_test.go +++ b/pkg/mockclient/verifications_test.go @@ -28,13 +28,13 @@ func TestVerifications(t *testing.T) { "atMost": 1 } }`}, - {"Verify the MockServer was called at least 0 times, and at most 1 times, for a given path, by using the default atMost.", CreateVerification(WhenRequestPath("/path"), ThenAtLeastCalls(1)), ` + {"Verify the MockServer was called at least 0 times, and at most 1 times, for a given path, by using the default atMost.", CreateVerification(WhenRequestPath("/path"), ThenAtLeastCalls(0)), ` { "httpRequest": { "path": "/path" }, "times": { - "atLeast": 1, + "atLeast": 0, "atMost": 1 } }`}, From 925d6320fef1323ddb2fbf228d729ed93f5c80b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sofia=20Fr=C3=B6man?= Date: Wed, 10 Apr 2019 13:46:40 +0200 Subject: [PATCH 4/4] Change function name. --- pkg/mockclient/expectations.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/mockclient/expectations.go b/pkg/mockclient/expectations.go index ebfa764..6af13ea 100644 --- a/pkg/mockclient/expectations.go +++ b/pkg/mockclient/expectations.go @@ -134,7 +134,7 @@ func WhenTimes(times int) ExpectationOption { return func(e *Expectation) *Expectation { e.Times = &Times{ RemainingTimes: times, - Unlimited: newBool(false), + Unlimited: boolPointer(false), } return e } @@ -196,7 +196,7 @@ func ThenResponseDelay(delay time.Duration) ExpectationOption { } } -func newBool(value bool) *bool { +func boolPointer(value bool) *bool { b := value return &b }