diff --git a/internal/cache/store_test.go b/internal/cache/store_test.go index caee1e0..2fd7647 100644 --- a/internal/cache/store_test.go +++ b/internal/cache/store_test.go @@ -12,9 +12,11 @@ import ( // TestCacheGetSet tests basic Get and Set operations. func TestCacheGetSet(t *testing.T) { ctx := context.Background() - client := NewRedisClient(redis.NewClient(&redis.Options{ - Addr: "localhost:6379", - }), metrics.New()) + rdb := redis.NewClient(&redis.Options{ + Addr: "127.0.0.1:6379", + }) + client := NewRedisClient(rdb, metrics.New()) + defer rdb.Close() // Test Set key := &CacheKey{Kind: "city", Code: "c146"} @@ -88,9 +90,11 @@ func TestCacheKeyString(t *testing.T) { // TestCacheAsideGetOrSet tests the cache-aside GetOrSetFuncPattern. func TestCacheAsideGetOrSet(t *testing.T) { ctx := context.Background() - client := NewRedisClient(redis.NewClient(&redis.Options{ - Addr: "localhost:6379", - }), metrics.New()) + rdb := redis.NewClient(&redis.Options{ + Addr: "127.0.0.1:6379", + }) + client := NewRedisClient(rdb, metrics.New()) + defer rdb.Close() fetchCallCount := 0 fetchFunc := func() ([]byte, error) { @@ -128,9 +132,11 @@ func TestCacheAsideGetOrSet(t *testing.T) { // TestCacheAsideGetCity tests GetCity with cache. func TestCacheAsideGetCity(t *testing.T) { ctx := context.Background() - client := NewRedisClient(redis.NewClient(&redis.Options{ - Addr: "localhost:6379", - }), metrics.New()) + rdb := redis.NewClient(&redis.Options{ + Addr: "127.0.0.1:6379", + }) + client := NewRedisClient(rdb, metrics.New()) + defer rdb.Close() fetchCallCount := 0 fetchFunc := func() ([]byte, error) { @@ -167,9 +173,11 @@ func TestCacheAsideGetCity(t *testing.T) { // TestCacheAsideGetSearch tests GetSearch with near-term and far-term TTL. func TestCacheAsideGetSearch(t *testing.T) { ctx := context.Background() - client := NewRedisClient(redis.NewClient(&redis.Options{ - Addr: "localhost:6379", - }), metrics.New()) + rdb := redis.NewClient(&redis.Options{ + Addr: "127.0.0.1:6379", + }) + client := NewRedisClient(rdb, metrics.New()) + defer rdb.Close() fetchNearTerm := func() ([]byte, error) { return []byte(`{"near_term":true}`), nil @@ -205,9 +213,11 @@ func TestCacheAsideGetSearch(t *testing.T) { // TestCacheInvalidate tests invalidation operations. func TestCacheInvalidate(t *testing.T) { ctx := context.Background() - client := NewRedisClient(redis.NewClient(&redis.Options{ - Addr: "localhost:6379", - }), metrics.New()) + rdb := redis.NewClient(&redis.Options{ + Addr: "127.0.0.1:6379", + }) + client := NewRedisClient(rdb, metrics.New()) + defer rdb.Close() // Set up some keys cityKey := &CacheKey{Kind: "city", Code: "c146"}