Skip to content

Commit

Permalink
Merge branch 'master' into pr-batch-example
Browse files Browse the repository at this point in the history
  • Loading branch information
pashagolub authored Aug 31, 2024
2 parents ad1dad8 + e681dfc commit 2f03bb6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ require (
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/text v0.15.0 // indirect
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -15,8 +16,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down
14 changes: 6 additions & 8 deletions pgxmock.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package pgxmock

import (
"context"
"errors"
"fmt"
"reflect"

Expand Down Expand Up @@ -554,33 +555,30 @@ func findExpectationFunc[ET expectationType[t], t any](c *pgxmock, method string
fulfilled++
continue
}

if expected, ok = next.(ET); ok {
err = cmp(expected)
if err == nil {
if err = cmp(expected); err == nil {
break
}
}
expected = nil
next.Unlock()
if c.ordered {
if (!ok || err != nil) && !next.required() {
next.Unlock()
if !next.required() {
continue
}
next.Unlock()
if err != nil {
return nil, err
}
return nil, fmt.Errorf("call to method %s, was not expected, next expectation is: %s", method, next)
}
next.Unlock()
}

if expected == nil {
msg := fmt.Sprintf("call to method %s was not expected", method)
if fulfilled == len(c.expectations) {
msg = "all expectations were already fulfilled, " + msg
}
return nil, fmt.Errorf(msg)
return nil, errors.New(msg)
}
defer expected.Unlock()

Expand Down
13 changes: 13 additions & 0 deletions pgxmock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1216,3 +1216,16 @@ func TestExpectReset(t *testing.T) {
mock.ExpectReset()
a.Error(mock.ExpectationsWereMet())
}

func TestDoubleUnlock(t *testing.T) {
mock, _ := NewConn()
mock.MatchExpectationsInOrder(false)
a := assert.New(t)

mock.ExpectExec("insert").WillReturnResult(NewResult("ok", 1))
mock.ExpectExec("update").WillReturnResult(NewResult("ok", 1))

_, err := mock.Exec(ctx, "foo")
a.Error(err)
a.NotPanics(func() { _ = mock.Ping(ctx) })
}

0 comments on commit 2f03bb6

Please sign in to comment.