redismock icon indicating copy to clipboard operation
redismock copied to clipboard

Can ForEachMaster be mocked/expected ?

Open meximonster opened this issue 3 years ago • 6 comments

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 ?

meximonster avatar Aug 15 '21 17:08 meximonster

Yes, some functions or commands are not supported, I plan to optimize it in the near future.

monkey92t avatar Aug 16 '21 02:08 monkey92t

Thank you!

meximonster avatar Aug 16 '21 06:08 meximonster

Hey, I am facing the same Problem. @monkey92t any thoughts / direction on how this might be implemented? I would like to help out here.

ChristophBleyer avatar Oct 04 '21 14:10 ChristophBleyer

Hello @monkey92t,

Does this apply to the Do command as well ? It cannot be mocked/expected ?

meximonster avatar Oct 14 '21 14:10 meximonster

same here

mnlprz avatar Feb 23 '23 20:02 mnlprz

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"))

guishoudaoge avatar Sep 22 '23 05:09 guishoudaoge