ananke/internal/execx/runner_additional_test.go

54 lines
1.7 KiB
Go
Raw Normal View History

package execx
import (
"context"
"strings"
"testing"
)
// TestRunnerRunFailureWithoutOutput runs one orchestration or CLI step.
// Signature: TestRunnerRunFailureWithoutOutput(t *testing.T).
// Why: covers error branch where command fails without producing output.
func TestRunnerRunFailureWithoutOutput(t *testing.T) {
r := &Runner{}
out, err := r.Run(context.Background(), "sh", "-c", "exit 3")
if err == nil {
t.Fatalf("expected failure")
}
if out != "" {
t.Fatalf("expected empty output, got %q", out)
}
}
// TestRunnerLogfNoLogger runs one orchestration or CLI step.
// Signature: TestRunnerLogfNoLogger(t *testing.T).
// Why: covers no-op logging path.
func TestRunnerLogfNoLogger(t *testing.T) {
r := &Runner{}
r.logf("hello %s", "world")
}
// TestRunnerCommandMissing runs one orchestration or CLI step.
// Signature: TestRunnerCommandMissing(t *testing.T).
// Why: covers false branch of command existence checks.
func TestRunnerCommandMissing(t *testing.T) {
r := &Runner{}
if r.CommandExists("definitely-not-a-real-command-ananke") {
t.Fatalf("expected missing command to be false")
}
}
// TestRunnerInjectsKubeconfigEnv runs one orchestration or CLI step.
// Signature: TestRunnerInjectsKubeconfigEnv(t *testing.T).
// Why: covers kubeconfig environment injection branch in command runner.
func TestRunnerInjectsKubeconfigEnv(t *testing.T) {
r := &Runner{Kubeconfig: "/tmp/test-kubeconfig"}
out, err := r.Run(context.Background(), "sh", "-c", "printf %s \"$KUBECONFIG\"")
if err != nil {
t.Fatalf("runner command failed: %v", err)
}
if strings.TrimSpace(out) != "/tmp/test-kubeconfig" {
t.Fatalf("expected kubeconfig env to propagate, got %q", out)
}
}