Skip to content

Commit 01392cc

Browse files
authored
feat(exp): fail test when mock calls were expected but not received (#542)
Ensure test failure when some call were expected, but were not received. e.g. we have a single mocked request, but the test does not generate any call, the test should fail.
1 parent 09a582a commit 01392cc

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

hcloud/exp/mockutil/http.go

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net/http"
66
"testing"
77

8+
"github.com/stretchr/testify/assert"
89
"github.com/stretchr/testify/require"
910
)
1011

@@ -33,6 +34,11 @@ func Handler(t *testing.T, requests []Request) http.HandlerFunc {
3334
t.Helper()
3435

3536
index := 0
37+
38+
t.Cleanup(func() {
39+
assert.EqualValues(t, len(requests), index, "expected more calls")
40+
})
41+
3642
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
3743
if testing.Verbose() {
3844
t.Logf("call %d: %s %s\n", index, r.Method, r.RequestURI)

0 commit comments

Comments
 (0)