rafaeljusto/redigomock

Mocking a call to `Do` that involves a `nil` parameter blows up.

Closed this issue · 2 comments

MrJoy commented

I have a call to Do, of the form Do("some_command", ..., nil, ...) and I would like to mock it. Unfortunately, when I do so, I get a panic, because implementsFuzzy blows up when given nil, due to the assumption that reflect.TypeOf(nil) will return a non-nil value.

A more durable construction might be:

func implementsFuzzy(input interface{}) bool {
	inputType := reflect.TypeOf(input)
	if inputType == nil {
		return false
	}
	return inputType.Implements(reflect.TypeOf((*FuzzyMatcher)(nil)).Elem())
}

Hey @MrJoy , nice one! Thanks for reporting. Would you like to open a PR for that to get the credits for the fix? Or can I fix it here?

MrJoy commented

Sorry, didn't see your comment until today! Thank you for taking care of that for me!