70 lines
2.1 KiB
Go
70 lines
2.1 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestConfigLoad(t *testing.T) {
|
|
os.Setenv("ALT_WORKER_HOST", "127.0.0.9")
|
|
os.Setenv("ALT_WORKER_PORT", "9999")
|
|
os.Setenv("ALT_WORKER_SOCKET_PATH", "/ws-test")
|
|
os.Setenv("ALT_WORKER_SCHEDULE_CONFIG", "/path/to/schedule.yaml")
|
|
defer func() {
|
|
os.Unsetenv("ALT_WORKER_HOST")
|
|
os.Unsetenv("ALT_WORKER_PORT")
|
|
os.Unsetenv("ALT_WORKER_SOCKET_PATH")
|
|
os.Unsetenv("ALT_WORKER_SCHEDULE_CONFIG")
|
|
}()
|
|
|
|
cfg := Load()
|
|
|
|
if cfg.Host != "127.0.0.9" {
|
|
t.Errorf("expected Host to be 127.0.0.9, got %q", cfg.Host)
|
|
}
|
|
if cfg.Port != 9999 {
|
|
t.Errorf("expected Port to be 9999, got %d", cfg.Port)
|
|
}
|
|
if cfg.SocketPath != "/ws-test" {
|
|
t.Errorf("expected SocketPath to be /ws-test, got %q", cfg.SocketPath)
|
|
}
|
|
if cfg.ScheduleConfigPath != "/path/to/schedule.yaml" {
|
|
t.Errorf("expected ScheduleConfigPath to be /path/to/schedule.yaml, got %q", cfg.ScheduleConfigPath)
|
|
}
|
|
if !cfg.SchedulerEnabled {
|
|
t.Errorf("expected SchedulerEnabled to be true, got false")
|
|
}
|
|
}
|
|
|
|
func TestConfigDefault(t *testing.T) {
|
|
os.Unsetenv("ALT_WORKER_HOST")
|
|
os.Unsetenv("ALT_WORKER_PORT")
|
|
os.Unsetenv("ALT_WORKER_SOCKET_PATH")
|
|
os.Unsetenv("DATABASE_URL")
|
|
os.Unsetenv("REDIS_URL")
|
|
os.Unsetenv("ALT_WORKER_SCHEDULE_CONFIG")
|
|
|
|
cfg := Load()
|
|
|
|
if cfg.Host != "127.0.0.1" {
|
|
t.Errorf("expected default Host to be 127.0.0.1, got %q", cfg.Host)
|
|
}
|
|
if cfg.Port != 18031 {
|
|
t.Errorf("expected default Port to be 18031, got %d", cfg.Port)
|
|
}
|
|
if cfg.SocketPath != "/socket" {
|
|
t.Errorf("expected default SocketPath to be /socket, got %q", cfg.SocketPath)
|
|
}
|
|
if cfg.DatabaseURL != "postgres://alt:alt@localhost:15430/alt?sslmode=disable" {
|
|
t.Errorf("expected default DatabaseURL to be postgres://alt:alt@localhost:15430/alt?sslmode=disable, got %q", cfg.DatabaseURL)
|
|
}
|
|
if cfg.RedisURL != "redis://localhost:16330/0" {
|
|
t.Errorf("expected default RedisURL to be redis://localhost:16330/0, got %q", cfg.RedisURL)
|
|
}
|
|
if cfg.ScheduleConfigPath != "" {
|
|
t.Errorf("expected default ScheduleConfigPath to be empty, got %q", cfg.ScheduleConfigPath)
|
|
}
|
|
if cfg.SchedulerEnabled {
|
|
t.Errorf("expected default SchedulerEnabled to be false, got true")
|
|
}
|
|
}
|