mock

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadOnlyTestFS

func ReadOnlyTestFS(fs vfs.FS) (vfs.FS, error)

func TestFS

func TestFS(root any) (vfs.FS, func(), error)

Types

type Mounter

type Mounter struct {
	ErrorOnMount   bool
	ErrorOnUnmount bool
	FakeMounter    mount.Interface
}

FakeMounter is a fake mounter for tests that can error out.

func NewMounter

func NewMounter() *Mounter

NewFakeMounter returns an FakeMounter with an instance of FakeMounter inside so we can use its functions

func (Mounter) GetMountPoints

func (e Mounter) GetMountPoints(device string) ([]mounter.MountPoint, error)

func (Mounter) GetMountRefs

func (e Mounter) GetMountRefs(pathname string) ([]string, error)

func (Mounter) IsMountPoint

func (e Mounter) IsMountPoint(file string) (bool, error)

func (Mounter) List

func (e Mounter) List() ([]mounter.MountPoint, error)

func (Mounter) Mount

func (e Mounter) Mount(source string, target string, fstype string, options []string) error

Mount will return an error if ErrorOnMount is true

func (Mounter) Unmount

func (e Mounter) Unmount(target string) error

Unmount will return an error if ErrorOnUnmount is true

type Runner

type Runner struct {
	ReturnValue []byte
	SideEffect  func(command string, args ...string) ([]byte, error)
	ReturnError error
	Logger      log.Logger
	// contains filtered or unexported fields
}

func NewRunner

func NewRunner() *Runner

func (*Runner) ClearCmds

func (r *Runner) ClearCmds()

func (Runner) CmdsMatch

func (r Runner) CmdsMatch(cmdList [][]string) error

CmdsMatch matches the commands list in order. Note HasPrefix is being used to evaluate the match, so expecting initial part of the command is enough to get a match. It facilitates testing commands with dynamic arguments (aka temporary files)

func (Runner) EnvsMatch

func (r Runner) EnvsMatch(envList [][]string) error

func (Runner) GetCmds

func (r Runner) GetCmds() [][]string

GetCmds returns the list of commands recorded by this FakeRunner instance this is helpful to debug tests

func (Runner) GetLogger

func (r Runner) GetLogger() log.Logger

func (Runner) IncludesCmds

func (r Runner) IncludesCmds(cmdList [][]string) error

IncludesCmds checks the given commands were executed in any order. Note it uses HasPrefix to match commands, see CmdsMatch.

func (Runner) MatchMilestones

func (r Runner) MatchMilestones(cmdList [][]string) error

MatchMilestones matches all the given commands were executed in the provided order. Note it uses HasPrefix to match commands, see CmdsMatch.

func (*Runner) Run

func (r *Runner) Run(command string, args ...string) ([]byte, error)

func (*Runner) RunContext

func (r *Runner) RunContext(_ context.Context, command string, args ...string) ([]byte, error)

func (*Runner) RunContextParseOutput

func (r *Runner) RunContextParseOutput(_ context.Context, stdoutH, _ func(string), command string, args ...string) error

func (*Runner) RunEnv

func (r *Runner) RunEnv(command string, envs []string, args ...string) ([]byte, error)

func (*Runner) SetLogger

func (r *Runner) SetLogger(logger log.Logger)

type Syscall

type Syscall struct {
	ErrorOnChroot bool
	// contains filtered or unexported fields
}

FakeSyscall is a test helper method to track calls to syscall It can also fail on Chroot command

func (*Syscall) Chdir

func (f *Syscall) Chdir(_ string) error

func (*Syscall) Chroot

func (f *Syscall) Chroot(path string) error

Chroot will store the chroot call It can return a failure if ErrorOnChroot is true

func (*Syscall) WasChrootCalledWith

func (f *Syscall) WasChrootCalledWith(path string) bool

WasChrootCalledWith is a helper method to check if Chroot was called with the given path

Jump to

Keyboard shortcuts

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