80 lines
2.9 KiB
Go
80 lines
2.9 KiB
Go
package main
|
|
|
|
import (
|
|
"io"
|
|
"log"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestRunStatusAndIntentReadOnly runs one orchestration or CLI step.
|
|
// Signature: TestRunStatusAndIntentReadOnly(t *testing.T).
|
|
// Why: keeps behavior explicit so startup/shutdown workflows remain maintainable as services evolve.
|
|
func TestRunStatusAndIntentReadOnly(t *testing.T) {
|
|
cfgPath := writeTestConfig(t)
|
|
logger := log.New(io.Discard, "", 0)
|
|
|
|
if err := runStatus(logger, []string{"--config", cfgPath}); err != nil {
|
|
t.Fatalf("runStatus failed: %v", err)
|
|
}
|
|
if err := runIntent(logger, []string{"--config", cfgPath}); err != nil {
|
|
t.Fatalf("runIntent read-only failed: %v", err)
|
|
}
|
|
}
|
|
|
|
// TestRunShutdownDryRunClusterOnly runs one orchestration or CLI step.
|
|
// Signature: TestRunShutdownDryRunClusterOnly(t *testing.T).
|
|
// Why: keeps behavior explicit so startup/shutdown workflows remain maintainable as services evolve.
|
|
func TestRunShutdownDryRunClusterOnly(t *testing.T) {
|
|
cfgPath := writeTestConfig(t)
|
|
logger := log.New(io.Discard, "", 0)
|
|
|
|
if err := runShutdown(logger, []string{"--config", cfgPath, "--mode", "cluster-only"}); err != nil {
|
|
t.Fatalf("runShutdown dry-run failed: %v", err)
|
|
}
|
|
}
|
|
|
|
// TestRunShutdownRejectsPoweroffMode runs one orchestration or CLI step.
|
|
// Signature: TestRunShutdownRejectsPoweroffMode(t *testing.T).
|
|
// Why: keeps behavior explicit so startup/shutdown workflows remain maintainable as services evolve.
|
|
func TestRunShutdownRejectsPoweroffMode(t *testing.T) {
|
|
cfgPath := writeTestConfig(t)
|
|
logger := log.New(io.Discard, "", 0)
|
|
|
|
err := runShutdown(logger, []string{"--config", cfgPath, "--mode", "poweroff"})
|
|
if err == nil {
|
|
t.Fatalf("expected poweroff mode rejection")
|
|
}
|
|
if !strings.Contains(err.Error(), "no longer powers off hosts") {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
}
|
|
|
|
// TestRunIntentWriteRequiresExecute runs one orchestration or CLI step.
|
|
// Signature: TestRunIntentWriteRequiresExecute(t *testing.T).
|
|
// Why: keeps behavior explicit so startup/shutdown workflows remain maintainable as services evolve.
|
|
func TestRunIntentWriteRequiresExecute(t *testing.T) {
|
|
cfgPath := writeTestConfig(t)
|
|
logger := log.New(io.Discard, "", 0)
|
|
|
|
err := runIntent(logger, []string{"--config", cfgPath, "--set", "normal"})
|
|
if err == nil {
|
|
t.Fatalf("expected write without --execute to fail")
|
|
}
|
|
if !strings.Contains(err.Error(), "without --execute") {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
}
|
|
|
|
// TestRunIntentWriteExecute runs one orchestration or CLI step.
|
|
// Signature: TestRunIntentWriteExecute(t *testing.T).
|
|
// Why: keeps behavior explicit so startup/shutdown workflows remain maintainable as services evolve.
|
|
func TestRunIntentWriteExecute(t *testing.T) {
|
|
cfgPath := writeTestConfig(t)
|
|
logger := log.New(io.Discard, "", 0)
|
|
|
|
if err := runIntent(logger, []string{"--config", cfgPath, "--set", "normal", "--reason", "test", "--source", "unit", "--execute"}); err != nil {
|
|
t.Fatalf("runIntent write failed: %v", err)
|
|
}
|
|
}
|