mock

package module
v0.0.0-...-1d905aa Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package mock provides a controllable implementation of invoke.Environment for testing purposes.

It allows defining expectations for command execution and file operations, enabling deterministic unit tests for code that builds upon the invoke library.

Usage:

m := mock.New()
m.OnCommand("git status").Return(0, "On branch main", "")
// pass 'm' to your logic

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteOutput

func WriteOutput(w io.Writer, content string) func(mock.Arguments)

WriteOutput is a helper to simulate output writing for mocked processes. Usage: mockProcess.On("Wait").Run(WriteOutput(cmd.Stdout, "output")).Return(nil).

Types

type Environment

type Environment struct {
	mock.Mock
}

Environment implements a mock invoke.Environment using testify/mock.

func New

func New() *Environment

New creates a new mock environment.

func (*Environment) Close

func (m *Environment) Close() error

Close mocks closing the environment.

func (*Environment) Download

func (m *Environment) Download(ctx context.Context, remotePath, localPath string, opts ...invoke.FileOption) error

Download mocks downloading a file from the remote environment.

func (*Environment) LookPath

func (m *Environment) LookPath(_ context.Context, file string) (string, error)

LookPath mocks looking up an executable path.

func (*Environment) Run

func (m *Environment) Run(ctx context.Context, cmd *invoke.Command) (*invoke.Result, error)

Run mocks running a command to completion.

func (*Environment) Start

func (m *Environment) Start(ctx context.Context, cmd *invoke.Command) (invoke.Process, error)

Start mocks starting a command asynchronously.

func (*Environment) TargetOS

func (m *Environment) TargetOS() invoke.TargetOS

TargetOS mocks returning the target operating system.

func (*Environment) Upload

func (m *Environment) Upload(ctx context.Context, localPath, remotePath string, opts ...invoke.FileOption) error

Upload mocks uploading a file to the remote environment.

type Process

type Process struct {
	mock.Mock
}

Process implements a mock invoke.Process using testify/mock.

func (*Process) Close

func (m *Process) Close() error

Close mocks closing the process.

func (*Process) Result

func (m *Process) Result() *invoke.Result

Result mocks returning the process result.

func (*Process) Signal

func (m *Process) Signal(sig os.Signal) error

Signal mocks sending a signal to the process.

func (*Process) Wait

func (m *Process) Wait() error

Wait mocks waiting for the process to complete.

Jump to

Keyboard shortcuts

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