Skip to content

Facing issue in mocking while migrating from go-redis, mockery mocks #972

@akshaykhairmode

Description

@akshaykhairmode

Hi @rueian

Currently facing mock issue in my repo for mocking the Cache() method. The Cache() method returns a concrete type of CachaCompat.

cacheCompat := mocks.NewCacheCompat(t)

stringCmd := &rueidiscompat.StringCmd{}
stringCmd.SetErr(rueidiscompat.Nil)
RedisClient.On("Cache", 100*time.Millisecond).Return(cacheCompat)
cacheCompat.On("Get", ctx, "key").Return(stringCmd)

Also creating an interface at my end does not work as mockery fails it with incorrect type.

panic: interface conversion: interface {} is *mocks.CacheCompat, not rueidiscompat.CacheCompat [recovered, repanicked]

Only solution which I see is to return the CacheCompat as an interface, what do you suggest?

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