ananke/testing/execx/runner_command_contract_test.go

67 lines
2.1 KiB
Go

package execxquality
import (
"context"
"strings"
"testing"
"scm.bstein.dev/bstein/ananke/internal/execx"
)
// TestRunnerRunSuccess runs one orchestration or CLI step.
// Signature: TestRunnerRunSuccess(t *testing.T).
// Why: keeps command execution success behavior stable after moving runner
// checks into the top-level testing module.
func TestRunnerRunSuccess(t *testing.T) {
runner := &execx.Runner{}
out, err := runner.Run(context.Background(), "sh", "-c", "printf ok")
if err != nil {
t.Fatalf("expected command success: %v", err)
}
if out != "ok" {
t.Fatalf("expected output ok, got %q", out)
}
}
// TestRunnerRunFailureIncludesOutput runs one orchestration or CLI step.
// Signature: TestRunnerRunFailureIncludesOutput(t *testing.T).
// Why: preserves failure-output behavior checks after split-module migration.
func TestRunnerRunFailureIncludesOutput(t *testing.T) {
runner := &execx.Runner{}
out, err := runner.Run(context.Background(), "sh", "-c", "echo boom >&2; exit 1")
if err == nil {
t.Fatalf("expected command failure")
}
if strings.TrimSpace(out) != "boom" {
t.Fatalf("expected stderr to be preserved, got %q", out)
}
}
// TestRunnerRunFailureWithoutOutput runs one orchestration or CLI step.
// Signature: TestRunnerRunFailureWithoutOutput(t *testing.T).
// Why: keeps the empty-output failure branch covered after root-module tests are removed.
func TestRunnerRunFailureWithoutOutput(t *testing.T) {
runner := &execx.Runner{}
out, err := runner.Run(context.Background(), "sh", "-c", "exit 3")
if err == nil {
t.Fatalf("expected failure")
}
if out != "" {
t.Fatalf("expected empty output, got %q", out)
}
}
// TestRunnerCommandDiscovery runs one orchestration or CLI step.
// Signature: TestRunnerCommandDiscovery(t *testing.T).
// Why: preserves both positive and negative command existence checks from the
// top-level testing module.
func TestRunnerCommandDiscovery(t *testing.T) {
runner := &execx.Runner{}
if !runner.CommandExists("sh") {
t.Fatalf("expected shell command to exist")
}
if runner.CommandExists("definitely-not-a-real-command-ananke") {
t.Fatalf("expected missing command to be false")
}
}