diff --git a/cmd/config.go b/cmd/config.go index 0d34d7da0..1a64df736 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -60,18 +60,20 @@ type RedisConfig struct { // GetSettings returns redis config parsed from moira config files. func (config *RedisConfig) GetSettings() redis.DatabaseConfig { return redis.DatabaseConfig{ - MasterName: config.MasterName, - Addrs: strings.Split(config.Addrs, ","), - Username: config.Username, - Password: config.Password, - MaxRetries: config.MaxRetries, - MetricsTTL: to.Duration(config.MetricsTTL), - DialTimeout: to.Duration(config.DialTimeout), - ReadTimeout: to.Duration(config.ReadTimeout), - WriteTimeout: to.Duration(config.WriteTimeout), - ReadOnly: config.ReadOnly, - RouteByLatency: config.RouteByLatency, - RouteRandomly: config.RouteRandomly, + MasterName: config.MasterName, + Addrs: strings.Split(config.Addrs, ","), + Username: config.Username, + Password: config.Password, + SentinelUsername: config.SentinelUsername, + SentinelPassword: config.SentinelPassword, + MaxRetries: config.MaxRetries, + MetricsTTL: to.Duration(config.MetricsTTL), + DialTimeout: to.Duration(config.DialTimeout), + ReadTimeout: to.Duration(config.ReadTimeout), + WriteTimeout: to.Duration(config.WriteTimeout), + ReadOnly: config.ReadOnly, + RouteByLatency: config.RouteByLatency, + RouteRandomly: config.RouteRandomly, } } diff --git a/cmd/config_test.go b/cmd/config_test.go new file mode 100644 index 000000000..f41583d00 --- /dev/null +++ b/cmd/config_test.go @@ -0,0 +1,61 @@ +package cmd + +import ( + "testing" + "time" + + "github.com/moira-alert/moira/database/redis" + . "github.com/smartystreets/goconvey/convey" +) + +func TestRedisConfig(t *testing.T) { + Convey("Test RedisConfig.GetSettings", t, func() { + Convey("With empty config", func() { + redisCfg := RedisConfig{} + + expected := redis.DatabaseConfig{ + Addrs: []string{""}, + } + databaseCfg := redisCfg.GetSettings() + So(databaseCfg, ShouldResemble, expected) + }) + + Convey("With filled config", func() { + redisCfg := RedisConfig{ + MasterName: "test-master", + Addrs: "redis1:6379", + SentinelUsername: "sentinel-user", + SentinelPassword: "sentinel-pass", + Username: "user", + Password: "pass", + MetricsTTL: "1m", + DialTimeout: "1m", + ReadTimeout: "1m", + WriteTimeout: "1m", + MaxRetries: 3, + ReadOnly: true, + RouteByLatency: true, + RouteRandomly: true, + } + + expected := redis.DatabaseConfig{ + MasterName: "test-master", + Addrs: []string{"redis1:6379"}, + SentinelUsername: "sentinel-user", + SentinelPassword: "sentinel-pass", + Username: "user", + Password: "pass", + MetricsTTL: time.Minute, + DialTimeout: time.Minute, + ReadTimeout: time.Minute, + WriteTimeout: time.Minute, + MaxRetries: 3, + ReadOnly: true, + RouteByLatency: true, + RouteRandomly: true, + } + databaseCfg := redisCfg.GetSettings() + So(databaseCfg, ShouldResemble, expected) + }) + }) +}