diff --git a/go.mod b/go.mod index abd17a7..f6b0525 100644 --- a/go.mod +++ b/go.mod @@ -4,9 +4,10 @@ go 1.19 require ( github.com/fatih/color v1.16.0 + github.com/mjc-gh/redis-test-hook v0.1.0 github.com/redis/go-redis/extra/rediscmd/v9 v9.0.5 - github.com/redis/go-redis/v9 v9.0.5 - github.com/stretchr/testify v1.8.2 + github.com/redis/go-redis/v9 v9.5.1 + github.com/stretchr/testify v1.9.0 ) require ( diff --git a/go.sum b/go.sum index 1e9ae40..3797a04 100644 --- a/go.sum +++ b/go.sum @@ -16,12 +16,16 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mjc-gh/redis-test-hook v0.1.0 h1:JpYPKhtNF8EdKm4FBOa0tJ3er1yaJUlnXZ7RSNihcm0= +github.com/mjc-gh/redis-test-hook v0.1.0/go.mod h1:w2hc7+/d23bEVg3BV1iQOIUn+wBWfqTVDfpFMs4ubkY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/redis/go-redis/extra/rediscmd/v9 v9.0.5 h1:EaDatTxkdHG+U3Bk4EUr+DZ7fOGwTfezUiUJMaIcaho= github.com/redis/go-redis/extra/rediscmd/v9 v9.0.5/go.mod h1:fyalQWdtzDBECAQFBJuQe5bzQ02jGd5Qcbgb97Flm7U= github.com/redis/go-redis/v9 v9.0.5 h1:CuQcn5HIEeK7BgElubPP8CGtE0KakrnbBSTLjathl5o= github.com/redis/go-redis/v9 v9.0.5/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk= +github.com/redis/go-redis/v9 v9.5.1 h1:H1X4D3yHPaYrkL5X06Wh6xNVM/pX0Ft4RV0vMGvLBh8= +github.com/redis/go-redis/v9 v9.5.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -29,6 +33,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= diff --git a/kredis_test.go b/kredis_test.go index e138713..92ba9cf 100644 --- a/kredis_test.go +++ b/kredis_test.go @@ -5,11 +5,13 @@ import ( "fmt" "testing" + redistesthooks "github.com/mjc-gh/redis-test-hook" "github.com/stretchr/testify/suite" ) type KredisTestSuite struct { suite.Suite + captureHook *redistesthooks.Hook } type testLogger struct{ stdLogger } @@ -24,10 +26,16 @@ func (suite *KredisTestSuite) SetupTest() { // TODO use a unique namespace for each test (thus potentially enabling // parallel tests) SetConfiguration("shared", "ns", "redis://localhost:6379/2") + SetConfiguration("capture", "ns", "redis://localhost:6379/2") SetConfiguration("badconn", "", "redis://localhost:1234/0") EnableDebugLogging() + suite.captureHook = redistesthooks.New() + + client, _, _ := getConnection("capture") + client.AddHook(suite.captureHook) + testWarnings = []string{} SetDebugLogger(&testLogger{}) } @@ -43,9 +51,12 @@ func (suite *KredisTestSuite) TearDownTest() { c.Del(ctx, key) } + suite.captureHook.Reset() + // Reset connections delete(connections, "shared") delete(connections, "badconn") + delete(connections, "capture") } // listen for 'go test' command --> run test methods diff --git a/proxy.go b/proxy.go index be8ca10..c4ef759 100644 --- a/proxy.go +++ b/proxy.go @@ -82,5 +82,5 @@ func (p *Proxy) RefreshTTL() (bool, error) { return false, nil } - return p.client.ExpireXX(p.ctx, p.key, p.expiresIn).Result() + return p.client.Expire(p.ctx, p.key, p.expiresIn).Result() } diff --git a/slot_test.go b/slot_test.go index 5ad22b7..b3dae49 100644 --- a/slot_test.go +++ b/slot_test.go @@ -1,7 +1,5 @@ package kredis -import "time" - func (s *KredisTestSuite) TestSlot() { slot, err := NewSlot("slot", 3) s.NoError(err) @@ -25,17 +23,13 @@ func (s *KredisTestSuite) TestSlot() { } func (s KredisTestSuite) TestSlotExpiry() { - slot, err := NewSlot("slot", 1, WithExpiry("1ms")) + slot, err := NewSlot("slot", 1, WithConfigName("capture"), WithExpiry("5s")) s.NoError(err) slot.Reserve() s.False(slot.IsAvailable()) - time.Sleep(2 * time.Millisecond) - - dur, err := slot.TTL() - s.NoError(err) - s.Equal(time.Duration(-1), dur) + s.Equal("EXPIRE ns:slot 5", s.captureHook.Captures[2].String()) } func (s *KredisTestSuite) TestSlotWithReserveCallback() {