Skip to content

Commit

Permalink
adding constructor unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mativm02 committed Jan 22, 2024
1 parent c393441 commit 4c4963d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions storage/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func NewRedisClusterPool(forceReconnect bool, config *RedisStorageConfig) *Redis
redisClusterSingleton = &RedisManager{}
redisClusterSingleton.kv = kv
redisClusterSingleton.list = l
redisClusterSingleton.conn = conn

return redisClusterSingleton
}
Expand Down
33 changes: 33 additions & 0 deletions storage/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"fmt"
"testing"
"time"

"github.com/TykTechnologies/storage/temporal/model"
"github.com/stretchr/testify/assert"
)

func TestRedisAddressConfiguration(t *testing.T) {
Expand Down Expand Up @@ -139,3 +142,33 @@ func TestRedisClusterStorageManager_GetAndDeleteSet(t *testing.T) {
})
}
}

func TestNewRedisClusterPool(t *testing.T) {
tcs := []struct {
name string
cfg *RedisStorageConfig
}{
{
name: "connect to localhost:6379",
cfg: &RedisStorageConfig{
Host: "localhost",
Port: 6379,
},
},
}

for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
pool := NewRedisClusterPool(false, tc.cfg)
if pool == nil {
t.Fatal("pool is nil")
}

assert.NotNil(t, pool.conn)
assert.NotNil(t, pool.kv)
assert.NotNil(t, pool.list)
assert.Equal(t, pool.conn.Type(), model.RedisV9Type)
assert.NoError(t, pool.conn.Ping(context.Background()))
})
}
}

0 comments on commit 4c4963d

Please sign in to comment.