feat(config): env-based configuration with validation
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLoadRequiresEncKey32Bytes(t *testing.T) {
|
||||
t.Setenv("DATABASE_URL", "postgres://x")
|
||||
t.Setenv("AUTH_USER", "admin")
|
||||
t.Setenv("AUTH_PASS", "pass")
|
||||
t.Setenv("SESSION_SECRET", "secret")
|
||||
t.Setenv("ENC_KEY", base64.StdEncoding.EncodeToString(make([]byte, 16))) // wrong size
|
||||
|
||||
if _, err := Load(); err == nil {
|
||||
t.Fatal("expected error for 16-byte ENC_KEY, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadDefaults(t *testing.T) {
|
||||
t.Setenv("DATABASE_URL", "postgres://x")
|
||||
t.Setenv("AUTH_USER", "admin")
|
||||
t.Setenv("AUTH_PASS", "pass")
|
||||
t.Setenv("SESSION_SECRET", "secret")
|
||||
t.Setenv("ENC_KEY", base64.StdEncoding.EncodeToString(make([]byte, 32)))
|
||||
|
||||
cfg, err := Load()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if cfg.HTTPAddr != ":8080" {
|
||||
t.Errorf("HTTPAddr = %q, want :8080", cfg.HTTPAddr)
|
||||
}
|
||||
if cfg.WorkerConcurrency != 4 {
|
||||
t.Errorf("WorkerConcurrency = %d, want 4", cfg.WorkerConcurrency)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user