textmachine/platform/internal/config/config_test.go

48 lines
1.2 KiB
Go

package config
import (
"testing"
"time"
)
func TestDefaultsAndOverrides(t *testing.T) {
c, err := Load()
if err != nil {
t.Fatal(err)
}
if c.Addr != "127.0.0.1:8080" {
t.Fatalf("default addr = %q; a control plane must not bind the world by default", c.Addr)
}
if c.Migrate {
t.Fatal("migrations must be opt-in")
}
t.Setenv("TM_PLATFORM_ADDR", ":9000")
t.Setenv("TM_PLATFORM_SESSION_IDLE", "30m")
t.Setenv("TM_PLATFORM_TRUSTED_ORIGINS", "https://app.example.org, https://desktop.example.org ")
c, err = Load()
if err != nil {
t.Fatal(err)
}
if c.Addr != ":9000" || c.SessionIdleTTL != 30*time.Minute {
t.Fatalf("config = %+v", c)
}
if len(c.TrustedOrigins) != 2 || c.TrustedOrigins[1] != "https://desktop.example.org" {
t.Fatalf("origins = %q", c.TrustedOrigins)
}
}
func TestImpossibleSessionWindowIsRefusedAtBoot(t *testing.T) {
t.Setenv("TM_PLATFORM_SESSION_IDLE", "100h")
t.Setenv("TM_PLATFORM_SESSION_MAX_AGE", "1h")
if _, err := Load(); err == nil {
t.Fatal("an idle window longer than the absolute one must fail at boot, not at 3am")
}
}
func TestMalformedDurationIsRefused(t *testing.T) {
t.Setenv("TM_PLATFORM_SESSION_IDLE", "fortnight")
if _, err := Load(); err == nil {
t.Fatal("want a parse error")
}
}