53 lines
1.7 KiB
Go
53 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestMainHelpSubprocess runs one orchestration or CLI step.
|
|
// Signature: TestMainHelpSubprocess(t *testing.T).
|
|
// Why: keeps behavior explicit so startup/shutdown workflows remain maintainable as services evolve.
|
|
func TestMainHelpSubprocess(t *testing.T) {
|
|
if os.Getenv("ANANKE_TEST_MAIN_HELP") == "1" {
|
|
os.Args = []string{"ananke", "help"}
|
|
main()
|
|
return
|
|
}
|
|
cmd := exec.Command(os.Args[0], "-test.run=TestMainHelpSubprocess")
|
|
cmd.Env = append(os.Environ(), "ANANKE_TEST_MAIN_HELP=1")
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("expected help subprocess success: %v\n%s", err, string(out))
|
|
}
|
|
if !strings.Contains(string(out), "Usage:") {
|
|
t.Fatalf("expected usage output, got:\n%s", string(out))
|
|
}
|
|
}
|
|
|
|
// TestMainUnknownCommandSubprocess runs one orchestration or CLI step.
|
|
// Signature: TestMainUnknownCommandSubprocess(t *testing.T).
|
|
// Why: keeps behavior explicit so startup/shutdown workflows remain maintainable as services evolve.
|
|
func TestMainUnknownCommandSubprocess(t *testing.T) {
|
|
if os.Getenv("ANANKE_TEST_MAIN_UNKNOWN") == "1" {
|
|
os.Args = []string{"ananke", "definitely-unknown"}
|
|
main()
|
|
return
|
|
}
|
|
cmd := exec.Command(os.Args[0], "-test.run=TestMainUnknownCommandSubprocess")
|
|
cmd.Env = append(os.Environ(), "ANANKE_TEST_MAIN_UNKNOWN=1")
|
|
out, err := cmd.CombinedOutput()
|
|
if err == nil {
|
|
t.Fatalf("expected unknown-command subprocess to fail")
|
|
}
|
|
exitErr, ok := err.(*exec.ExitError)
|
|
if !ok {
|
|
t.Fatalf("expected exit error type, got %T (%v)", err, err)
|
|
}
|
|
if exitErr.ExitCode() != 2 {
|
|
t.Fatalf("expected exit code 2 for usage failure, got %d\n%s", exitErr.ExitCode(), string(out))
|
|
}
|
|
}
|