executor

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package executor provides the CommandExecutor interface and implementations for running Wireshark CLI tools (tshark, capinfos, editcap, mergecap). RealExecutor calls actual binaries; MockExecutor enables testing without Wireshark installed.

Index

Constants

View Source
const DefaultTimeout = 60 * time.Second

DefaultTimeout is the maximum execution time for any single command.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandExecutor

type CommandExecutor interface {
	// Execute runs a CLI command and returns stdout, stderr, and any error.
	Execute(ctx context.Context, binary string, args []string) (stdout []byte, stderr []byte, err error)

	// BinaryPath resolves the full path to a Wireshark CLI tool.
	// Supports: tshark, capinfos, editcap, mergecap, dumpcap.
	BinaryPath(name string) (string, error)
}

CommandExecutor is the primary port for executing Wireshark CLI tools. All tool handlers depend on this interface, enabling testing without real tshark binaries installed.

type MockCall

type MockCall struct {
	Binary string
	Args   []string
}

MockCall records a single command execution.

type MockExecutor

type MockExecutor struct {
	// Responses maps "binary args..." to a mock response.
	Responses map[string]MockResponse
	// Calls records all executed commands for assertions.
	Calls []MockCall
	// DefaultResponse is returned when no matching response is found.
	DefaultResponse *MockResponse
}

MockExecutor is a test double for CommandExecutor. Set the response fields before calling Execute.

func NewMockExecutor

func NewMockExecutor() *MockExecutor

NewMockExecutor creates a mock executor with an empty response map.

func (*MockExecutor) BinaryPath

func (m *MockExecutor) BinaryPath(name string) (string, error)

func (*MockExecutor) Execute

func (m *MockExecutor) Execute(_ context.Context, binary string, args []string) ([]byte, []byte, error)

type MockResponse

type MockResponse struct {
	Stdout []byte
	Stderr []byte
	Err    error
}

MockResponse holds canned output for a mocked command.

type RealExecutor

type RealExecutor struct {
	// contains filtered or unexported fields
}

RealExecutor executes commands against real Wireshark CLI binaries.

func NewRealExecutor

func NewRealExecutor(logger *slog.Logger, wiresharkDir string) *RealExecutor

NewRealExecutor creates a new executor that runs real CLI commands.

func (*RealExecutor) BinaryPath

func (e *RealExecutor) BinaryPath(name string) (string, error)

func (*RealExecutor) Execute

func (e *RealExecutor) Execute(ctx context.Context, binary string, args []string) ([]byte, []byte, error)

Jump to

Keyboard shortcuts

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