ananke/cmd/ananke/test_helpers_test.go

48 lines
1.3 KiB
Go

package main
import (
"fmt"
"os"
"path/filepath"
"testing"
)
// writeTestConfig runs one orchestration or CLI step.
// Signature: writeTestConfig(t *testing.T) string.
// Why: command-level tests need a stable on-disk config path that satisfies
// validation without depending on host-global files.
func writeTestConfig(t *testing.T) string {
t.Helper()
tmp := t.TempDir()
stateDir := filepath.Join(tmp, "state")
if err := os.MkdirAll(stateDir, 0o755); err != nil {
t.Fatalf("mkdir state dir: %v", err)
}
cfgPath := filepath.Join(tmp, "ananke.yaml")
raw := fmt.Sprintf(`
control_planes: [titan-0a]
workers: [titan-04]
ssh_user: atlas
ssh_port: 2277
ssh_node_hosts:
titan-0a: 192.168.22.11
titan-04: 192.168.22.30
ssh_managed_nodes: [titan-0a, titan-04]
expected_flux_branch: main
expected_flux_source_url: ssh://git@scm.bstein.dev:2242/bstein/titan-iac.git
iac_repo_path: %q
ups:
enabled: false
state:
dir: %q
reports_dir: %q
run_history_path: %q
lock_path: %q
intent_path: %q
`, tmp, stateDir, filepath.Join(stateDir, "reports"), filepath.Join(stateDir, "runs.json"), filepath.Join(stateDir, "ananke.lock"), filepath.Join(stateDir, "intent.json"))
if err := os.WriteFile(cfgPath, []byte(raw), 0o644); err != nil {
t.Fatalf("write config: %v", err)
}
return cfgPath
}