go-redis / redismock

Redis client Mock
https://redis.uptrace.dev
BSD 2-Clause "Simplified" License
271 stars 59 forks source link

Type issues with v9.0.3 and cache v9 #83

Open Goldziher opened 9 months ago

Goldziher commented 9 months ago

Hi there,

Given the following dependencies (from go.mod):

    github.com/go-redis/cache/v9 v9.0.0
    github.com/go-redis/redismock/v9 v9.0.3

I get this issue:

# github.com/go-redis/redismock/v9
../../../go/pkg/mod/github.com/go-redis/redismock/v9@v9.0.3/mock.go:905:20: m.factory.GetBit undefined (type redis.Cmdable has no field or method GetBit)
../../../go/pkg/mod/github.com/go-redis/redismock/v9@v9.0.3/mock.go:912:20: m.factory.SetBit undefined (type redis.Cmdable has no field or method SetBit)
../../../go/pkg/mod/github.com/go-redis/redismock/v9@v9.0.3/mock.go:919:20: m.factory.BitCount undefined (type redis.Cmdable has no field or method BitCount)
../../../go/pkg/mod/github.com/go-redis/redismock/v9@v9.0.3/mock.go:926:20: m.factory.BitOpAnd undefined (type redis.Cmdable has no field or method BitOpAnd)
../../../go/pkg/mod/github.com/go-redis/redismock/v9@v9.0.3/mock.go:933:20: m.factory.BitOpOr undefined (type redis.Cmdable has no field or method BitOpOr)
../../../go/pkg/mod/github.com/go-redis/redismock/v9@v9.0.3/mock.go:940:20: m.factory.BitOpXor undefined (type redis.Cmdable has no field or method BitOpXor)
../../../go/pkg/mod/github.com/go-redis/redismock/v9@v9.0.3/mock.go:947:20: m.factory.BitOpNot undefined (type redis.Cmdable has no field or method BitOpNot)
../../../go/pkg/mod/github.com/go-redis/redismock/v9@v9.0.3/mock.go:954:20: m.factory.BitPos undefined (type redis.Cmdable has no field or method BitPos)
../../../go/pkg/mod/github.com/go-redis/redismock/v9@v9.0.3/mock.go:961:20: m.factory.BitPosSpan undefined (type redis.Cmdable has no field or method BitPosSpan)
../../../go/pkg/mod/github.com/go-redis/redismock/v9@v9.0.3/mock.go:968:20: m.factory.BitField undefined (type redis.Cmdable has no field or method BitField)
../../../go/pkg/mod/github.com/go-redis/redismock/v9@v9.0.3/mock.go:968:20: too many errors

I am executing the following test:

t.Run("Caches values as expected", func(t *testing.T) {
        _, err := rediscache.New("redis://redis:6379")
        assert.Nil(t, err)

        db, mockRedis := redismock.NewClientMock() //nolint: typecheck

        rediscache.SetClient(cache.New(&cache.Options{
            Redis: db,
        }))

        client := rediscache.GetClient()

        key := "john"

        val := &cache.Item{
            TTL:   time.Minute,
            Key:   key,
            Value: "doe",
        }

        expected, _ := client.Marshal("doe")

        mockRedis.ExpectSet(key, expected, time.Minute).SetVal("OK")
        setErr := client.Set(val)
        assert.NoError(t, setErr)
    })
snoepkast commented 9 months ago

This is caused by a new release of go-redis which was released yesterday. By downgrading to v9.1.0 the issue is fixed, however an update to redismock would be nice.

bertold commented 9 months ago

I added a PR to address this: https://github.com/go-redis/redismock/pull/84/files . This is my first contribution, so excuse me if I missed anything.