| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package infrastructures_test |
||
| 2 | |||
| 3 | import ( |
||
| 4 | "testing" |
||
| 5 | |||
| 6 | "github.com/memnix/memnix-rest/infrastructures" |
||
| 7 | ) |
||
| 8 | |||
| 9 | func TestGetRedisClient(t *testing.T) { |
||
| 10 | // Initialize RedisManager instance |
||
| 11 | redisConf := infrastructures.RedisConfig{ |
||
| 12 | Addr: "localhost:6379", |
||
| 13 | Password: "", |
||
| 14 | MinIdleConns: 10, |
||
| 15 | PoolSize: 100, |
||
| 16 | PoolTimeout: 30, |
||
| 17 | } |
||
| 18 | redisManager := infrastructures.NewRedisInstance(redisConf) |
||
| 19 | |||
| 20 | // Connect to Redis |
||
| 21 | err := redisManager.ConnectRedis() |
||
| 22 | if err != nil { |
||
| 23 | t.Errorf("Failed to connect to Redis: %v", err) |
||
| 24 | } |
||
| 25 | |||
| 26 | // Get Redis client |
||
| 27 | client := redisManager.GetRedisClient() |
||
| 28 | if client == nil { |
||
| 29 | t.Error("Failed to get Redis client") |
||
| 30 | } |
||
| 31 | |||
| 32 | // Close Redis connection |
||
| 33 | err = redisManager.CloseRedis() |
||
| 34 | if err != nil { |
||
| 35 | t.Errorf("Failed to close Redis connection: %v", err) |
||
| 36 | } |
||
| 37 | } |
||
| 38 | |||
| 39 | func TestRedisManager_RedisWithConfig(t *testing.T) { |
||
| 40 | // Initialize RedisManager instance |
||
| 41 | redisManager := &infrastructures.RedisManager{} |
||
| 42 | |||
| 43 | // Set Redis config |
||
| 44 | redisConf := infrastructures.RedisConfig{ |
||
| 45 | Addr: "localhost:6379", |
||
| 46 | Password: "", |
||
| 47 | MinIdleConns: 10, |
||
| 48 | PoolSize: 100, |
||
| 49 | PoolTimeout: 30, |
||
| 50 | } |
||
| 51 | redisManager.RedisWithConfig(redisConf) |
||
| 52 | |||
| 53 | // Check if Redis config is set correctly |
||
| 54 | if redisManager.Redisconfig != redisConf { |
||
| 55 | t.Errorf("Redis config not set correctly") |
||
| 56 | } |
||
| 58 |