github.com/msales/pkg/v3@v3.24.0/cache/redis_test.go (about) 1 package cache_test 2 3 import ( 4 "net" 5 "testing" 6 7 "github.com/msales/pkg/v3/cache" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 var ( 12 testRedisServer = "localhost:6379" 13 skipRedis = false 14 ) 15 16 func init() { 17 c, err := net.Dial("tcp", testRedisServer) 18 if err != nil { 19 skipRedis = true 20 return 21 } 22 c.Write([]byte("SELECT 1\r\n")) 23 c.Write([]byte("FLUSHDB\r\n")) 24 c.Close() 25 } 26 27 func TestRedisCache(t *testing.T) { 28 if skipRedis { 29 t.Skipf("skipping test; no running server at %s", testRedisServer) 30 } 31 32 c, err := cache.NewRedis("redis://" + testRedisServer + "/1") 33 assert.NoError(t, err) 34 35 runCacheTests(t, c) 36 }