92 lines
2.9 KiB
Go
92 lines
2.9 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// TestLoadFailsOnMissingFile runs one orchestration or CLI step.
|
|
// Signature: TestLoadFailsOnMissingFile(t *testing.T).
|
|
// Why: covers file-read failure handling for config load path.
|
|
func TestLoadFailsOnMissingFile(t *testing.T) {
|
|
if _, err := Load(filepath.Join(t.TempDir(), "missing.yaml")); err == nil {
|
|
t.Fatalf("expected missing file error")
|
|
}
|
|
}
|
|
|
|
// TestLoadFailsOnBadYAML runs one orchestration or CLI step.
|
|
// Signature: TestLoadFailsOnBadYAML(t *testing.T).
|
|
// Why: covers YAML decode failure handling for config load path.
|
|
func TestLoadFailsOnBadYAML(t *testing.T) {
|
|
cfgPath := filepath.Join(t.TempDir(), "ananke.yaml")
|
|
if err := os.WriteFile(cfgPath, []byte(":\n- invalid"), 0o644); err != nil {
|
|
t.Fatalf("write bad config: %v", err)
|
|
}
|
|
if _, err := Load(cfgPath); err == nil {
|
|
t.Fatalf("expected decode error")
|
|
}
|
|
}
|
|
|
|
// TestLoadFailsValidationOnBrokenValues runs one orchestration or CLI step.
|
|
// Signature: TestLoadFailsValidationOnBrokenValues(t *testing.T).
|
|
// Why: covers Load->Validate error propagation.
|
|
func TestLoadFailsValidationOnBrokenValues(t *testing.T) {
|
|
cfgPath := filepath.Join(t.TempDir(), "ananke.yaml")
|
|
raw := `
|
|
control_planes: [titan-0a]
|
|
expected_flux_branch: main
|
|
expected_flux_source_url: ssh://git@scm.bstein.dev:2242/bstein/titan-iac.git
|
|
iac_repo_path: /opt/titan-iac
|
|
startup:
|
|
service_checklist:
|
|
- name: x
|
|
url: https://ok.example
|
|
timeout_seconds: 0
|
|
`
|
|
if err := os.WriteFile(cfgPath, []byte(raw), 0o644); err != nil {
|
|
t.Fatalf("write config: %v", err)
|
|
}
|
|
if _, err := Load(cfgPath); err == nil {
|
|
t.Fatalf("expected validation failure")
|
|
}
|
|
}
|
|
|
|
// TestLoadKeepsExplicitServiceChecklist runs one orchestration or CLI step.
|
|
// Signature: TestLoadKeepsExplicitServiceChecklist(t *testing.T).
|
|
// Why: host recovery configs must be able to keep a narrow, explicit checklist
|
|
// without silently inheriting the full default service catalog.
|
|
func TestLoadKeepsExplicitServiceChecklist(t *testing.T) {
|
|
cfgPath := filepath.Join(t.TempDir(), "ananke.yaml")
|
|
raw := `
|
|
control_planes: [titan-0a]
|
|
expected_flux_branch: main
|
|
expected_flux_source_url: ssh://git@scm.bstein.dev:2242/bstein/titan-iac.git
|
|
iac_repo_path: /opt/titan-iac
|
|
startup:
|
|
service_checklist_explicit_only: true
|
|
service_checklist:
|
|
- name: gitea-api
|
|
url: https://scm.bstein.dev/api/healthz
|
|
accepted_statuses: [200]
|
|
body_contains: pass
|
|
timeout_seconds: 12
|
|
ups:
|
|
enabled: false
|
|
`
|
|
if err := os.WriteFile(cfgPath, []byte(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.Startup.ServiceChecklist) != 1 {
|
|
t.Fatalf("expected 1 explicit service check, got %d", len(cfg.Startup.ServiceChecklist))
|
|
}
|
|
if cfg.Startup.ServiceChecklist[0].Name != "gitea-api" {
|
|
t.Fatalf("expected explicit gitea-api check, got %q", cfg.Startup.ServiceChecklist[0].Name)
|
|
}
|
|
}
|