cosmos-sdk/orm/testing/ormmocks/match.go
Aaron Craelius 77ac8fa378
feat(orm): add mock hooks (#11135)
* feat(orm): add mock hooks

* add hooks

* add tests

* update docs

* Update orm/testing/ormmocks/docs.go

Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com>

* add Backend.WithHooks method

Co-authored-by: Tyler <48813565+technicallyty@users.noreply.github.com>
2022-02-08 11:56:53 -05:00

30 lines
690 B
Go

package ormmocks
import (
"github.com/golang/mock/gomock"
"github.com/google/go-cmp/cmp"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/testing/protocmp"
)
// Code adapted from MIT-licensed https://github.com/budougumi0617/cmpmock/blob/master/diffmatcher.go
// Eq returns a gomock.Matcher which uses go-cmp to compare protobuf messages.
func Eq(message proto.Message) gomock.Matcher {
return &protoEq{message: message}
}
type protoEq struct {
message interface{}
diff string
}
func (p protoEq) Matches(x interface{}) bool {
p.diff = cmp.Diff(x, p.message, protocmp.Transform())
return len(p.diff) == 0
}
func (p protoEq) String() string {
return p.diff
}