Skip to content

Commit

Permalink
feat(exp): fail test when mock calls were expected but not received (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
jooola authored Oct 31, 2024
1 parent 09a582a commit 01392cc
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions hcloud/exp/mockutil/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

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

index := 0

t.Cleanup(func() {
assert.EqualValues(t, len(requests), index, "expected more calls")
})

return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if testing.Verbose() {
t.Logf("call %d: %s %s\n", index, r.Method, r.RequestURI)
Expand Down

0 comments on commit 01392cc

Please sign in to comment.