Documentation
¶
Index ¶
- type Executor
- type Mock
- func (m *Mock) CurrentUser() (*user.User, error)
- func (m *Mock) DirExists(path string) bool
- func (m *Mock) FileExists(path string) bool
- func (m *Mock) GOOS() string
- func (m *Mock) Getenv(key string) string
- func (m *Mock) Glob(pattern string) ([]string, error)
- func (m *Mock) HomeDir(_ string) (string, error)
- func (m *Mock) Hostname() (string, error)
- func (m *Mock) IsRoot() bool
- func (m *Mock) LookPath(name string) (string, error)
- func (m *Mock) ReadDir(path string) ([]os.DirEntry, error)
- func (m *Mock) ReadFile(path string) ([]byte, error)
- func (m *Mock) Run(_ context.Context, name string, args ...string) (string, string, int, error)
- func (m *Mock) RunAsUser(ctx context.Context, _ string, command string) (string, error)
- func (m *Mock) RunWithTimeout(ctx context.Context, _ time.Duration, name string, args ...string) (string, string, int, error)
- func (m *Mock) SetCommand(stdout, stderr string, exitCode int, name string, args ...string)
- func (m *Mock) SetCommandError(err error, name string, args ...string)
- func (m *Mock) SetDir(path string)
- func (m *Mock) SetDirEntries(path string, entries []os.DirEntry)
- func (m *Mock) SetEnv(key, value string)
- func (m *Mock) SetFile(path string, content []byte)
- func (m *Mock) SetFileInfo(path string, info os.FileInfo)
- func (m *Mock) SetGlob(pattern string, matches []string)
- func (m *Mock) SetHomeDir(h string)
- func (m *Mock) SetHostname(h string)
- func (m *Mock) SetIsRoot(v bool)
- func (m *Mock) SetPath(name, path string)
- func (m *Mock) SetUsername(u string)
- func (m *Mock) Stat(path string) (os.FileInfo, error)
- type Real
- func (r *Real) CurrentUser() (*user.User, error)
- func (r *Real) DirExists(path string) bool
- func (r *Real) FileExists(path string) bool
- func (r *Real) GOOS() string
- func (r *Real) Getenv(key string) string
- func (r *Real) Glob(pattern string) ([]string, error)
- func (r *Real) HomeDir(username string) (string, error)
- func (r *Real) Hostname() (string, error)
- func (r *Real) IsRoot() bool
- func (r *Real) LookPath(name string) (string, error)
- func (r *Real) ReadDir(path string) ([]os.DirEntry, error)
- func (r *Real) ReadFile(path string) ([]byte, error)
- func (r *Real) Run(ctx context.Context, name string, args ...string) (string, string, int, error)
- func (r *Real) RunAsUser(ctx context.Context, username, command string) (string, error)
- func (r *Real) RunWithTimeout(ctx context.Context, timeout time.Duration, name string, args ...string) (string, string, int, error)
- func (r *Real) Stat(path string) (os.FileInfo, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Executor ¶
type Executor interface {
// Run executes a command and returns stdout, stderr, and exit code.
Run(ctx context.Context, name string, args ...string) (stdout, stderr string, exitCode int, err error)
// RunWithTimeout executes a command with a timeout.
RunWithTimeout(ctx context.Context, timeout time.Duration, name string, args ...string) (stdout, stderr string, exitCode int, err error)
// RunAsUser runs a shell command as a specific user (for root -> user delegation).
RunAsUser(ctx context.Context, username, command string) (string, error)
// LookPath searches for an executable in PATH.
LookPath(name string) (string, error)
// FileExists checks if a file exists and is not a directory.
FileExists(path string) bool
// DirExists checks if a directory exists.
DirExists(path string) bool
// ReadFile reads a file's contents.
ReadFile(path string) ([]byte, error)
// ReadDir lists directory entries.
ReadDir(path string) ([]os.DirEntry, error)
// Stat returns file info.
Stat(path string) (os.FileInfo, error)
// Hostname returns the system hostname.
Hostname() (string, error)
// Getenv reads an environment variable.
Getenv(key string) string
// IsRoot returns true if the process is running as root.
IsRoot() bool
// CurrentUser returns the current OS user.
CurrentUser() (*user.User, error)
// HomeDir returns the home directory for a given username.
HomeDir(username string) (string, error)
// Glob returns filenames matching a pattern.
Glob(pattern string) ([]string, error)
// GOOS returns the runtime operating system.
GOOS() string
}
Executor defines the interface for all OS interactions. Every detector depends on this interface, enabling full unit-test coverage via mocks.
type Mock ¶
type Mock struct {
// contains filtered or unexported fields
}
Mock implements Executor for unit testing.
func (*Mock) FileExists ¶
func (*Mock) RunWithTimeout ¶
func (*Mock) SetCommand ¶
func (*Mock) SetCommandError ¶
func (*Mock) SetHomeDir ¶
func (*Mock) SetHostname ¶
func (*Mock) SetUsername ¶
type Real ¶
type Real struct{}
Real implements Executor using actual OS calls.