From 921abeee7649faa3386b65b2b82557b51e88bf81 Mon Sep 17 00:00:00 2001 From: Danil Tarasov <87192879+almostinf@users.noreply.github.com> Date: Fri, 20 Sep 2024 13:20:47 +0300 Subject: [PATCH] cherry-pick 9e9068832b757030aec49d21e9bd4cbed616a873 --- .github/workflows/publish-packages.yml | 4 +- cmd/config.go | 20 +++++----- cmd/config_test.go | 55 ++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 cmd/config_test.go diff --git a/.github/workflows/publish-packages.yml b/.github/workflows/publish-packages.yml index 8b5f534bf..f64dfcb8c 100644 --- a/.github/workflows/publish-packages.yml +++ b/.github/workflows/publish-packages.yml @@ -12,10 +12,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up Ruby 2.6 + - name: Set up Ruby 3.3 uses: ruby/setup-ruby@v1 with: - ruby-version: 2.6 + ruby-version: 3.3 - name: Install fpm run: gem install fpm diff --git a/cmd/config.go b/cmd/config.go index 267db3edc..6698d2b0c 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -50,15 +50,17 @@ 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), + 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), } } diff --git a/cmd/config_test.go b/cmd/config_test.go new file mode 100644 index 000000000..0e5fef80d --- /dev/null +++ b/cmd/config_test.go @@ -0,0 +1,55 @@ +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, + } + + 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, + } + databaseCfg := redisCfg.GetSettings() + So(databaseCfg, ShouldResemble, expected) + }) + }) +}