updating github.com/golang/mock to v1.2.0

This commit is contained in:
Davanum Srinivas
2019-06-14 10:58:41 -04:00
parent 0861b3f30f
commit 03c222ca09
7 changed files with 464 additions and 187 deletions

View File

@@ -22,7 +22,7 @@ import (
// A Matcher is a representation of a class of values.
// It is used to represent the valid or expected arguments to a mocked method.
type Matcher interface {
// Matches returns whether y is a match.
// Matches returns whether x is a match.
Matches(x interface{}) bool
// String describes what the matcher matches.
@@ -85,6 +85,18 @@ func (n notMatcher) String() string {
return "not(" + n.m.String() + ")"
}
type assignableToTypeOfMatcher struct {
targetType reflect.Type
}
func (m assignableToTypeOfMatcher) Matches(x interface{}) bool {
return reflect.TypeOf(x).AssignableTo(m.targetType)
}
func (m assignableToTypeOfMatcher) String() string {
return "is assignable to " + m.targetType.Name()
}
// Constructors
func Any() Matcher { return anyMatcher{} }
func Eq(x interface{}) Matcher { return eqMatcher{x} }
@@ -95,3 +107,16 @@ func Not(x interface{}) Matcher {
}
return notMatcher{Eq(x)}
}
// AssignableToTypeOf is a Matcher that matches if the parameter to the mock
// function is assignable to the type of the parameter to this function.
//
// Example usage:
//
// dbMock.EXPECT().
// Insert(gomock.AssignableToTypeOf(&EmployeeRecord{})).
// Return(errors.New("DB error"))
//
func AssignableToTypeOf(x interface{}) Matcher {
return assignableToTypeOfMatcher{reflect.TypeOf(x)}
}