redismock
redismock copied to clipboard
Can ForEachMaster be mocked/expected ?
Hello!
I am not able to test a function that uses the ForEachMaster method. The error returned is "redis: cluster has no nodes" and i cannot add nodes to the redis.ClusterClient created by NewClusterMock() because it takes no arguments. Am i missing something ?
Yes, some functions or commands are not supported, I plan to optimize it in the near future.
Thank you!
Hey, I am facing the same Problem. @monkey92t any thoughts / direction on how this might be implemented? I would like to help out here.
Hello @monkey92t,
Does this apply to the Do command as well ? It cannot be mocked/expected ?
same here
same here
I found a way to do this
db2, kvsMocker2 := redismock.NewClientMock()
var temp *red.ClusterClient
p := gomonkey.ApplyMethod(reflect.TypeOf(temp), "ForEachMaster", func(_ *red.ClusterClient, ctx context.Context, fn func(ctx context.Context, client *red.Client) error) error {
return fn(ctx, db2)
})
defer p.Reset()
kvsMocker2.ExpectScan(uint64(0), "ut-test", 100).SetErr(fmt.Errorf("Mock REDIS SCAN() return error"))