6408342a7f
Add table-driven rootCmd.Execute() tests for the node, job, cert, doctor, audit, status, version, and node-capacity subcommand families. Each test runs against a temp ORCA_HOME and asserts stdout/stderr/exit via the existing initTestEnv/resetRootFlags/discardWriter helpers (RESEARCH §1.2). extend resetRootFlags to also reset the per-command flag-bound globals so tests don't leak state between runs. daemon.go is excluded from the ≥70% target (documented in node_test.go): the daemon command starts a long-running mTLS server whose lifecycle is covered by internal/daemon/server_test.go; only its --pprof flag registration is verified here (daemon_test.go). Coverage: go test -cover ./internal/cli → 76.2% overall (78.7% by -func), which includes daemon.go's untested RunE; the non-daemon files exceed 70% comfortably. go test -race PASS. ---ci--- project: orca phase: 1 milestone: v0.8 status: execute ---/ci---
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package cli
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestStatusText(t *testing.T) {
|
|
resetRootFlags(t)
|
|
var buf bytes.Buffer
|
|
rootCmd.SetOut(&buf)
|
|
rootCmd.SetErr(&buf)
|
|
rootCmd.SetArgs([]string{"status"})
|
|
if err := rootCmd.Execute(); err != nil {
|
|
t.Fatalf("status: %v", err)
|
|
}
|
|
out := buf.String()
|
|
if !strings.Contains(out, "orca daemon status") {
|
|
t.Errorf("status text output unexpected: %s", out)
|
|
}
|
|
if !strings.Contains(out, "version") {
|
|
t.Errorf("status output missing version: %s", out)
|
|
}
|
|
}
|
|
|
|
func TestStatusJSON(t *testing.T) {
|
|
resetRootFlags(t)
|
|
var buf bytes.Buffer
|
|
rootCmd.SetOut(&buf)
|
|
rootCmd.SetErr(&buf)
|
|
rootCmd.SetArgs([]string{"status", "--json"})
|
|
if err := rootCmd.Execute(); err != nil {
|
|
t.Fatalf("status --json: %v", err)
|
|
}
|
|
var info map[string]any
|
|
if err := json.Unmarshal(bytes.TrimSpace(buf.Bytes()), &info); err != nil {
|
|
t.Fatalf("unmarshal status json: %v\n%s", err, buf.String())
|
|
}
|
|
if info["daemon"] != "stopped" {
|
|
t.Errorf("status json daemon = %v, want stopped", info["daemon"])
|
|
}
|
|
if info["api_addr"] != "https://localhost:8443" {
|
|
t.Errorf("status json api_addr = %v, want https://localhost:8443", info["api_addr"])
|
|
}
|
|
}
|