exec

package
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package exec provides an abstraction for executing podman commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Executor

type Executor interface {
	// Run executes a podman command, writing stdout and stderr to the provided writers.
	// Returns an error if the command fails.
	Run(ctx context.Context, stdout, stderr io.Writer, args ...string) error

	// Output executes a podman command and returns its standard output.
	// Stderr is written to the provided writer.
	// Returns an error if the command fails.
	Output(ctx context.Context, stderr io.Writer, args ...string) ([]byte, error)

	// RunInteractive executes a podman command with stdin/stdout/stderr connected to the terminal.
	// This is used for interactive sessions where user input is required.
	// Returns an error if the command fails.
	RunInteractive(ctx context.Context, args ...string) error
}

Executor provides an interface for executing podman commands.

func New

func New(podmanPath string) Executor

New creates a new Executor instance using the given podman executable path. The path can be a bare name ("podman") or an absolute path ("/usr/bin/podman").

type FakeExecutor

type FakeExecutor struct {
	// RunFunc is called when Run is invoked. If nil, Run returns nil.
	RunFunc func(ctx context.Context, args ...string) error

	// OutputFunc is called when Output is invoked. If nil, Output returns empty bytes.
	OutputFunc func(ctx context.Context, args ...string) ([]byte, error)

	// RunInteractiveFunc is called when RunInteractive is invoked. If nil, RunInteractive returns nil.
	RunInteractiveFunc func(ctx context.Context, args ...string) error

	// RunCalls tracks all calls to Run with their arguments.
	RunCalls [][]string

	// OutputCalls tracks all calls to Output with their arguments.
	OutputCalls [][]string

	// RunInteractiveCalls tracks all calls to RunInteractive with their arguments.
	RunInteractiveCalls [][]string
}

FakeExecutor is a fake implementation of Executor for testing.

func NewFake

func NewFake() *FakeExecutor

NewFake creates a new FakeExecutor.

func (*FakeExecutor) AssertOutputCalledWith

func (f *FakeExecutor) AssertOutputCalledWith(t interface {
	Errorf(format string, args ...interface{})
}, expectedArgs ...string)

AssertOutputCalledWith checks if Output was called with the expected arguments.

func (*FakeExecutor) AssertRunCalledWith

func (f *FakeExecutor) AssertRunCalledWith(t interface {
	Errorf(format string, args ...interface{})
}, expectedArgs ...string)

AssertRunCalledWith checks if Run was called with the expected arguments.

func (*FakeExecutor) AssertRunInteractiveCalledWith

func (f *FakeExecutor) AssertRunInteractiveCalledWith(t interface {
	Errorf(format string, args ...interface{})
}, expectedArgs ...string)

AssertRunInteractiveCalledWith checks if RunInteractive was called with the expected arguments.

func (*FakeExecutor) AssertRunNotCalledWith added in v0.6.0

func (f *FakeExecutor) AssertRunNotCalledWith(t interface {
	Errorf(format string, args ...interface{})
}, expectedArgs ...string)

AssertRunNotCalledWith checks that Run was never called with the expected arguments.

func (*FakeExecutor) Output

func (f *FakeExecutor) Output(ctx context.Context, stderr io.Writer, args ...string) ([]byte, error)

Output executes the OutputFunc if set, otherwise returns empty bytes.

func (*FakeExecutor) Run

func (f *FakeExecutor) Run(ctx context.Context, stdout, stderr io.Writer, args ...string) error

Run executes the RunFunc if set, otherwise returns nil.

func (*FakeExecutor) RunInteractive

func (f *FakeExecutor) RunInteractive(ctx context.Context, args ...string) error

RunInteractive executes the RunInteractiveFunc if set, otherwise returns nil.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL