go-rejson icon indicating copy to clipboard operation
go-rejson copied to clipboard

Mocking ReJSON in a mock redis server

Open kpiyush17 opened this issue 5 years ago • 3 comments

Is there any way to mock rejson in a mocked Redis server in golang?

I am able to mock a Redis server using something like this using miniredis and redismock

func newTestRedis() (*redismock.ClientMock, *redis.Client) {
	mr, err := miniredis.Run()
	if err != nil {
		panic(err)
	}
	client := redis.NewClient(&redis.Options{
		Addr: mr.Addr(),
	})
	return redismock.NewNiceMock(client.Client), client
}

It is able to do normal Redis operations like Get, Set but since I am using ReJSON module, I am not able to run any ReJSON commands on that.

Thanks

kpiyush17 avatar Dec 24 '19 05:12 kpiyush17

You can use something like mockery and testify to generate mocks using the ReJSON interface - https://github.com/nitishm/go-rejson/blob/master/rejson.go#L17

nitishm avatar Dec 25 '19 22:12 nitishm

But If I use the ReJSON interface to generate mocks, I have to create a struct(other than Handler) that implements all the methods of the ReJSON interface even if I am not using that method. Can you provide an example?

kpiyush17 avatar Dec 26 '19 12:12 kpiyush17

Has anyone solved this?

morcano avatar Sep 25 '23 15:09 morcano