From 900db58043af6ebbdcd81563e008add425ae9d2e Mon Sep 17 00:00:00 2001 From: Vladimir Zagainov Date: Thu, 20 Aug 2026 17:56:05 +0300 Subject: [PATCH] fix(test): use REDIS_ADDR environment variable in cron test mocks to match CI service hostname --- cmd/cron/station_status_test.go | 66 ++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/cmd/cron/station_status_test.go b/cmd/cron/station_status_test.go index 13d6e61..ca5a123 100644 --- a/cmd/cron/station_status_test.go +++ b/cmd/cron/station_status_test.go @@ -14,7 +14,16 @@ import ( ) func newMockMonitor(id string, tripCount int, scheduleFunc func(context.Context, string) (int, error)) *StationMonitor { - rc := redis.NewClient(&redis.Options{Addr: "localhost:6379"}) + // Read Redis address from environment, default to localhost:6379 + redisAddr := os.Getenv("REDIS_ADDR") + if redisAddr == "" { + redisAddr = "localhost:6379" + } + rc := redis.NewClient(&redis.Options{ + Addr: redisAddr, + Password: "", + DB: 0, + }) yc := yandex.NewClient("test-key") monitor := &StationMonitor{ @@ -40,7 +49,16 @@ const testMonitorID = "test-station" // gets status "active" and zero-trip day count resets to 0. func TestProcessStation_WithTrips(t *testing.T) { t.Helper() - rc := redis.NewClient(&redis.Options{Addr: "localhost:6379"}) + // Read Redis address from environment, default to localhost:6379 + redisAddr := os.Getenv("REDIS_ADDR") + if redisAddr == "" { + redisAddr = "localhost:6379" + } + rc := redis.NewClient(&redis.Options{ + Addr: redisAddr, + Password: "", + DB: 0, + }) defer rc.Close() ctx := context.Background() @@ -84,7 +102,16 @@ func TestProcessStation_WithTrips(t *testing.T) { // with 0 trips increments the zero-trip day count. func TestProcessStation_ZeroTrips_IncrementsCount(t *testing.T) { t.Helper() - rc := redis.NewClient(&redis.Options{Addr: "localhost:6379"}) + // Read Redis address from environment, default to localhost:6379 + redisAddr := os.Getenv("REDIS_ADDR") + if redisAddr == "" { + redisAddr = "localhost:6379" + } + rc := redis.NewClient(&redis.Options{ + Addr: redisAddr, + Password: "", + DB: 0, + }) defer rc.Close() ctx := context.Background() @@ -128,7 +155,16 @@ func TestProcessStation_ZeroTrips_IncrementsCount(t *testing.T) { // with 3 consecutive days of zero trips gets status "closed". func TestProcessStation_ZeroTrips_3Days_Closes(t *testing.T) { t.Helper() - rc := redis.NewClient(&redis.Options{Addr: "localhost:6379"}) + // Read Redis address from environment, default to localhost:6379 + redisAddr := os.Getenv("REDIS_ADDR") + if redisAddr == "" { + redisAddr = "localhost:6379" + } + rc := redis.NewClient(&redis.Options{ + Addr: redisAddr, + Password: "", + DB: 0, + }) defer rc.Close() ctx := context.Background() @@ -190,7 +226,16 @@ func TestProcessStation_ZeroTrips_3Days_Closes(t *testing.T) { // closed due to 3 zero-trip days gets reactivated when trips resume. func TestProcessStation_Reactivation_AfterClosure(t *testing.T) { t.Helper() - rc := redis.NewClient(&redis.Options{Addr: "localhost:6379"}) + // Read Redis address from environment, default to localhost:6379 + redisAddr := os.Getenv("REDIS_ADDR") + if redisAddr == "" { + redisAddr = "localhost:6379" + } + rc := redis.NewClient(&redis.Options{ + Addr: redisAddr, + Password: "", + DB: 0, + }) defer rc.Close() ctx := context.Background() @@ -240,7 +285,16 @@ func TestProcessStation_Reactivation_AfterClosure(t *testing.T) { // and that it reactivates when trips resume. func TestAutoClosureChronology(t *testing.T) { t.Helper() - rc := redis.NewClient(&redis.Options{Addr: "localhost:6379"}) + // Read Redis address from environment, default to localhost:6379 + redisAddr := os.Getenv("REDIS_ADDR") + if redisAddr == "" { + redisAddr = "localhost:6379" + } + rc := redis.NewClient(&redis.Options{ + Addr: redisAddr, + Password: "", + DB: 0, + }) defer rc.Close() ctx := context.Background()