зеркало из https://github.com/golang/mock.git
Fix handling of nil interface parameters being passed to Do funcs.
This commit is contained in:
Родитель
ae48011f41
Коммит
1d31a78edb
|
@ -203,7 +203,12 @@ func (c *Call) call(args []interface{}) (rets []interface{}, action func()) {
|
|||
doArgs := make([]reflect.Value, len(args))
|
||||
ft := c.doFunc.Type()
|
||||
for i := 0; i < ft.NumIn(); i++ {
|
||||
doArgs[i] = reflect.ValueOf(args[i])
|
||||
if args[i] != nil {
|
||||
doArgs[i] = reflect.ValueOf(args[i])
|
||||
} else {
|
||||
// Use the zero value for the arg.
|
||||
doArgs[i] = reflect.Zero(ft.In(i))
|
||||
}
|
||||
}
|
||||
action = func() { c.doFunc.Call(doArgs) }
|
||||
}
|
||||
|
|
|
@ -52,6 +52,15 @@ func TestRemember(t *testing.T) {
|
|||
if calledString != "blah" {
|
||||
t.Fatalf(`Uh oh. %q != "blah"`, calledString)
|
||||
}
|
||||
|
||||
// Use Do with a nil arg.
|
||||
mockIndex.EXPECT().Put("nil-key", gomock.Any()).Do(func(key string, value interface{}) {
|
||||
if value != nil {
|
||||
t.Errorf("Put did not pass through nil; got %v", value)
|
||||
}
|
||||
})
|
||||
mockIndex.EXPECT().NillableRet()
|
||||
user.Remember(mockIndex, []string{"nil-key"}, []interface{}{nil})
|
||||
}
|
||||
|
||||
func TestGrabPointer(t *testing.T) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче