Skip to content

Commands which return slices cannot be mocked #27

Open
@ideasculptor

Description

@ideasculptor

There are plenty of commands mocked which purport to return StringSlice or IntSlice, but there are no tests which exercise them. When I attempted to test code which returns a slice from a command, I always receive an error:

redis: unexpected type=[]int64 for Slice

which is not at all surprising when you look at the code here: https://github.com/go-redis/redis/blob/cc09f96b8fcabfa25bff2654209c8b711cc9c561/command.go#L375

It always stores the response val for a command as []interface{} and only creates a strongly typed slice after first selecting for []interface{} and then copying each value into a new, strongly typed slice. A strongly typed slice does not satisfy []interface{}

The mock code, on the other hand, assigns a strongly typed slice directly into the command's return val, which causes the call to Slice() to always throw an exception about the wrong type. It seems that SetVal for ExpectedIntSlice and ExpectedStringSlice should both take []interface{} rather than []int64 and []string respectively, or else it should copy into an []interface{} when copying the slice passed to SetVal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions