exec

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: MIT Imports: 8 Imported by: 21

README

Codacy Badge Codacy Badge

Make it be easy to writing unit tests when it's about the Go runtime.

Documentation

Index

Constants

View Source
const (
	// OSLinux is the alias of Linux
	OSLinux = "linux"
	// OSDarwin is the alias of Darwin
	OSDarwin = "darwin"
	// OSWindows is the alias of Windows
	OSWindows = "windows"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Execer

type Execer interface {
	LookPath(string) (string, error)
	Command(name string, arg ...string) ([]byte, error)
	RunCommand(name string, arg ...string) (err error)
	RunCommandWithEnv(name string, argv, envv []string, stdout, stderr io.Writer) (err error)
	RunCommandInDir(name, dir string, args ...string) error
	RunCommandAndReturn(name, dir string, args ...string) (result string, err error)
	RunCommandWithSudo(name string, args ...string) (err error)
	RunCommandWithBuffer(name, dir string, stdout, stderr *bytes.Buffer, args ...string) error
	RunCommandWithIO(name, dir string, stdout, stderr io.Writer, p chan Process, args ...string) error
	SystemCall(name string, argv []string, envv []string) (err error)
	MkdirAll(path string, perm os.FileMode) error
	OS() string
	Arch() string
	Getenv(string) string
	Setenv(string, string) error
	WithContext(context.Context) Execer
}

Execer is an interface for OS-related operations

func NewDefaultExecer added in v0.0.2

func NewDefaultExecer() Execer

func NewDefaultExecerWithContext added in v0.0.2

func NewDefaultExecerWithContext(ctx context.Context) Execer

type FakeExecer

type FakeExecer struct {
	ExpectError         error
	ExpectLookPathError error
	ExpectOutput        string
	ExpectErrOutput     string
	ExpectOS            string
	ExpectArch          string
	ExpectLookPath      string
	Env                 map[string]string
}

FakeExecer is for the unit test purposes

func (*FakeExecer) Arch

func (f *FakeExecer) Arch() string

Arch returns the os arch

func (*FakeExecer) Command

func (f *FakeExecer) Command(name string, arg ...string) ([]byte, error)

Command is a fake method

func (*FakeExecer) Getenv added in v0.0.5

func (f *FakeExecer) Getenv(key string) string

Getenv returns the env value by key

func (*FakeExecer) LookPath

func (f *FakeExecer) LookPath(path string) (string, error)

LookPath is a fake method

func (*FakeExecer) MkdirAll

func (f *FakeExecer) MkdirAll(path string, perm os.FileMode) error

MkdirAll is the wrapper of os.MkdirAll

func (*FakeExecer) OS

func (f *FakeExecer) OS() string

OS returns the os name

func (*FakeExecer) RunCommand

func (f *FakeExecer) RunCommand(name string, arg ...string) error

RunCommand runs a command

func (*FakeExecer) RunCommandAndReturn

func (f *FakeExecer) RunCommandAndReturn(name, dir string, args ...string) (result string, err error)

RunCommandAndReturn is a fake method

func (*FakeExecer) RunCommandInDir

func (f *FakeExecer) RunCommandInDir(name, dir string, args ...string) error

RunCommandInDir is a fake method

func (*FakeExecer) RunCommandWithBuffer

func (f *FakeExecer) RunCommandWithBuffer(name, dir string, stdout, stderr *bytes.Buffer, args ...string) error

RunCommandWithBuffer is a fake method

func (*FakeExecer) RunCommandWithEnv added in v0.0.2

func (f *FakeExecer) RunCommandWithEnv(name string, argv, envv []string, stdout, stderr io.Writer) error

RunCommandWithEnv is a fake method

func (*FakeExecer) RunCommandWithIO

func (f *FakeExecer) RunCommandWithIO(name, dir string, stdout, stderr io.Writer, p chan Process, args ...string) error

RunCommandWithIO is a fake method

func (*FakeExecer) RunCommandWithSudo

func (f *FakeExecer) RunCommandWithSudo(name string, args ...string) (err error)

RunCommandWithSudo is a fake method

func (*FakeExecer) Setenv added in v0.0.5

func (f *FakeExecer) Setenv(key, value string) error

Setenv sets the key-value pair into the env

func (*FakeExecer) SystemCall

func (f *FakeExecer) SystemCall(name string, argv []string, envv []string) error

SystemCall is a fake method

func (*FakeExecer) WithContext added in v0.0.3

func (f *FakeExecer) WithContext(ctx context.Context) Execer

type Process added in v0.0.4

type Process interface {
	Signal(sig os.Signal) error
	Kill() error
	Release() error
	Wait() (*os.ProcessState, error)
}

Jump to

Keyboard shortcuts

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