- Add worker storage layer with PostgreSQL/sqlc setup - Add migration files for worker backbone schema - Add job runner and built-in jobs implementation - Add Redis key definitions for worker state management - Archive socket-session-loop milestone (completed/renamed) - Update roadmap current.md and foundation-alignment phase - Add socket endpoint integration and runtime smoke tests - Add infra-check, worker-storage-check, worker-storage-gen CLI tools - Update API socket server and config - Add pubspec dependencies and client socket endpoint changes - Add config tests for API and worker services
77 lines
2 KiB
Go
77 lines
2 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestLoadDefaults(t *testing.T) {
|
|
// Ensure env vars are clean for default test
|
|
envs := []string{"DATABASE_URL", "REDIS_URL", "ALT_REDIS_KEY_PREFIX", "ALT_WORKER_QUEUE"}
|
|
for _, env := range envs {
|
|
if val, ok := os.LookupEnv(env); ok {
|
|
defer os.Setenv(env, val)
|
|
os.Unsetenv(env)
|
|
} else {
|
|
defer os.Unsetenv(env)
|
|
}
|
|
}
|
|
|
|
cfg := Load()
|
|
|
|
expectedDB := "postgres://alt:alt@localhost:5432/alt?sslmode=disable"
|
|
if cfg.DatabaseURL != expectedDB {
|
|
t.Errorf("expected DatabaseURL %q, got %q", expectedDB, cfg.DatabaseURL)
|
|
}
|
|
|
|
expectedRedis := "redis://localhost:6379/0"
|
|
if cfg.RedisURL != expectedRedis {
|
|
t.Errorf("expected RedisURL %q, got %q", expectedRedis, cfg.RedisURL)
|
|
}
|
|
|
|
expectedPrefix := "alt"
|
|
if cfg.RedisKeyPrefix != expectedPrefix {
|
|
t.Errorf("expected RedisKeyPrefix %q, got %q", expectedPrefix, cfg.RedisKeyPrefix)
|
|
}
|
|
|
|
expectedQueue := "default"
|
|
if cfg.WorkerQueue != expectedQueue {
|
|
t.Errorf("expected WorkerQueue %q, got %q", expectedQueue, cfg.WorkerQueue)
|
|
}
|
|
}
|
|
|
|
func TestLoadEnvOverrides(t *testing.T) {
|
|
envs := map[string]string{
|
|
"DATABASE_URL": "postgres://user:pass@host:5432/db",
|
|
"REDIS_URL": "redis://redis-host:6379/1",
|
|
"ALT_REDIS_KEY_PREFIX": "custom-prefix",
|
|
"ALT_WORKER_QUEUE": "custom-queue",
|
|
}
|
|
|
|
for k, v := range envs {
|
|
if val, ok := os.LookupEnv(k); ok {
|
|
defer os.Setenv(k, val)
|
|
} else {
|
|
defer os.Unsetenv(k)
|
|
}
|
|
os.Setenv(k, v)
|
|
}
|
|
|
|
cfg := Load()
|
|
|
|
if cfg.DatabaseURL != envs["DATABASE_URL"] {
|
|
t.Errorf("expected DatabaseURL %q, got %q", envs["DATABASE_URL"], cfg.DatabaseURL)
|
|
}
|
|
|
|
if cfg.RedisURL != envs["REDIS_URL"] {
|
|
t.Errorf("expected RedisURL %q, got %q", envs["REDIS_URL"], cfg.RedisURL)
|
|
}
|
|
|
|
if cfg.RedisKeyPrefix != envs["ALT_REDIS_KEY_PREFIX"] {
|
|
t.Errorf("expected RedisKeyPrefix %q, got %q", envs["ALT_REDIS_KEY_PREFIX"], cfg.RedisKeyPrefix)
|
|
}
|
|
|
|
if cfg.WorkerQueue != envs["ALT_WORKER_QUEUE"] {
|
|
t.Errorf("expected WorkerQueue %q, got %q", envs["ALT_WORKER_QUEUE"], cfg.WorkerQueue)
|
|
}
|
|
}
|