fix(test): use REDIS_ADDR environment variable in cron test mocks to match CI service hostname
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user