redismock icon indicating copy to clipboard operation
redismock copied to clipboard

Type issues with v9.0.3 and cache v9

Open Goldziher opened this issue 2 years ago • 2 comments

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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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)
	})

Goldziher avatar Sep 21 '23 09:09 Goldziher

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.

snoepkast avatar Sep 21 '23 14:09 snoepkast

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.

bertold avatar Sep 25 '23 18:09 bertold