96 lines
2.5 KiB
Go
96 lines
2.5 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestLoadAcceptsUPSTargets(t *testing.T) {
|
|
tmp := t.TempDir()
|
|
cfgPath := filepath.Join(tmp, "hecate.yaml")
|
|
raw := `
|
|
control_planes: [titan-0a, titan-0b, titan-0c]
|
|
expected_flux_branch: main
|
|
iac_repo_path: /opt/titan-iac
|
|
ups:
|
|
enabled: true
|
|
provider: nut
|
|
targets:
|
|
- name: pyrphoros
|
|
target: pyrphoros@localhost
|
|
shutdown:
|
|
default_budget_seconds: 300
|
|
state:
|
|
run_history_path: /tmp/runs.json
|
|
lock_path: /tmp/hecate.lock
|
|
`
|
|
if err := os.WriteFile(cfgPath, []byte(strings.TrimSpace(raw)), 0o644); err != nil {
|
|
t.Fatalf("write config: %v", err)
|
|
}
|
|
|
|
cfg, err := Load(cfgPath)
|
|
if err != nil {
|
|
t.Fatalf("load config: %v", err)
|
|
}
|
|
if len(cfg.UPS.Targets) != 1 || cfg.UPS.Targets[0].Target != "pyrphoros@localhost" {
|
|
t.Fatalf("unexpected UPS targets: %#v", cfg.UPS.Targets)
|
|
}
|
|
}
|
|
|
|
func TestValidateForwardShutdownRequiresConfigPath(t *testing.T) {
|
|
cfg := defaults()
|
|
cfg.Coordination.ForwardShutdownHost = "titan-db"
|
|
cfg.Coordination.ForwardShutdownConfig = ""
|
|
if err := cfg.Validate(); err == nil {
|
|
t.Fatalf("expected validation error for missing forward_shutdown_config")
|
|
}
|
|
}
|
|
|
|
func TestValidateRejectsUnknownRole(t *testing.T) {
|
|
cfg := defaults()
|
|
cfg.Coordination.Role = "unknown"
|
|
if err := cfg.Validate(); err == nil {
|
|
t.Fatalf("expected validation error for unknown coordination role")
|
|
}
|
|
}
|
|
|
|
func TestValidateRejectsUnknownEtcdRestoreControlPlane(t *testing.T) {
|
|
cfg := defaults()
|
|
cfg.Startup.EtcdRestoreControlPlane = "titan-missing"
|
|
if err := cfg.Validate(); err == nil {
|
|
t.Fatalf("expected validation error for unknown etcd restore control plane")
|
|
}
|
|
}
|
|
|
|
func TestLoadSetsCoordinationGuardDefaults(t *testing.T) {
|
|
tmp := t.TempDir()
|
|
cfgPath := filepath.Join(tmp, "hecate.yaml")
|
|
raw := `
|
|
control_planes: [titan-0a, titan-0b, titan-0c]
|
|
expected_flux_branch: main
|
|
iac_repo_path: /opt/titan-iac
|
|
coordination:
|
|
role: coordinator
|
|
ups:
|
|
enabled: false
|
|
state:
|
|
run_history_path: /tmp/runs.json
|
|
lock_path: /tmp/hecate.lock
|
|
`
|
|
if err := os.WriteFile(cfgPath, []byte(strings.TrimSpace(raw)), 0o644); err != nil {
|
|
t.Fatalf("write config: %v", err)
|
|
}
|
|
cfg, err := Load(cfgPath)
|
|
if err != nil {
|
|
t.Fatalf("load config: %v", err)
|
|
}
|
|
if cfg.Coordination.StartupGuardMaxAgeSec <= 0 {
|
|
t.Fatalf("expected startup guard max age default > 0, got %d", cfg.Coordination.StartupGuardMaxAgeSec)
|
|
}
|
|
if cfg.Startup.EtcdRestoreControlPlane == "" {
|
|
t.Fatalf("expected startup etcd restore control plane default to be set")
|
|
}
|
|
}
|