system

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package system contains interfaces for OS related APIs, intended to be used for dependency injection to facilitate unit testing.

The naming of the methods in this package is not very Go-idiomatic because the user of this package usually composes the interfaces in this package into one interface.

For example, the `Executable` method of `ExecutableFinder` should have been named as `Find` according to Go idiom, but it will be unreadable if the interface is embedded in another interface. For instance,

type SystemDeps interface {
	system.ExecutableFinder
	// other methods
}
var deps SystemDeps
deps.Executable() // in favor of deps.Find()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AbsFilePath added in v1.1.0

type AbsFilePath interface {
	FilePathAbs(elem string) (string, error)
}

AbsFilePath mocks out filepath.Abs.

type EnvChecker added in v0.4.0

type EnvChecker interface {
	LookupEnv(key string) (string, bool)
}

EnvChecker mocks out os.LookupEnv.

type EnvGetter

type EnvGetter interface {
	Env(key string) string
}

EnvGetter mocks out os.Getenv.

type EnvironGetter

type EnvironGetter interface {
	Environ() []string
}

EnvironGetter mocks out os.Environ.

type ExecutableFinder

type ExecutableFinder interface {
	Executable() (string, error)
}

ExecutableFinder mocks out os.Executable.

type FilePathJoiner

type FilePathJoiner interface {
	FilePathJoin(elem ...string) string
}

FilePathJoiner mocks out filepath.Join.

type FilePathToSlash added in v1.1.0

type FilePathToSlash interface {
	FilePathToSlash(elem string) string
}

FilePathToSlash mocks out filepath.ToSlash.

type PipeGetter added in v1.0.0

type PipeGetter interface {
	Pipe() (*os.File, *os.File, error)
}

PipeGetter mocks out os.Pipe.

type RuntimeArchGetter added in v0.5.0

type RuntimeArchGetter interface {
	Arch() string
}

RuntimeArchGetter mocks out runtime.GOARCH.

type RuntimeCPUGetter

type RuntimeCPUGetter interface {
	NumCPU() int
}

RuntimeCPUGetter mocks out runtime.NumCPU.

type RuntimeOSGetter added in v0.5.0

type RuntimeOSGetter interface {
	OS() string
}

RuntimeOSGetter mocks out runtime.GOOS.

type StdLib

type StdLib struct{}

StdLib implements the interfaces defined in system.go via standard library functions.

func NewStdLib

func NewStdLib() *StdLib

func (*StdLib) Arch added in v0.5.0

func (s *StdLib) Arch() string

func (*StdLib) Env

func (s *StdLib) Env(key string) string

func (*StdLib) Environ

func (s *StdLib) Environ() []string
func (s *StdLib) EvalSymlinks(path string) (string, error)

func (*StdLib) Executable

func (s *StdLib) Executable() (string, error)

func (*StdLib) FilePathAbs added in v1.1.0

func (s *StdLib) FilePathAbs(elem string) (string, error)

func (*StdLib) FilePathJoin

func (s *StdLib) FilePathJoin(elem ...string) string

func (*StdLib) FilePathToSlash added in v1.1.0

func (s *StdLib) FilePathToSlash(elem string) string

func (*StdLib) GetUserHome added in v1.1.0

func (s *StdLib) GetUserHome() (string, error)

func (*StdLib) GetWd added in v1.1.0

func (s *StdLib) GetWd() (string, error)

func (*StdLib) LookupEnv added in v0.4.0

func (s *StdLib) LookupEnv(key string) (string, bool)

func (*StdLib) NumCPU

func (s *StdLib) NumCPU() int

func (*StdLib) OS added in v0.5.0

func (s *StdLib) OS() string

func (*StdLib) Pipe added in v1.0.0

func (s *StdLib) Pipe() (*os.File, *os.File, error)

func (*StdLib) ReadMemStats

func (s *StdLib) ReadMemStats(st *runtime.MemStats)

func (*StdLib) SetStdout added in v1.0.0

func (s *StdLib) SetStdout(w *os.File)

func (*StdLib) Stderr

func (s *StdLib) Stderr() *os.File

func (*StdLib) Stdin

func (s *StdLib) Stdin() *os.File

func (*StdLib) Stdout

func (s *StdLib) Stdout() *os.File

type StderrGetter

type StderrGetter interface {
	Stderr() *os.File
}

StderrGetter mocks out os.Stderr.

type StdinGetter

type StdinGetter interface {
	Stdin() *os.File
}

StdinGetter mocks out os.Stdin.

type StdoutGetter

type StdoutGetter interface {
	Stdout() *os.File
}

StdoutGetter mocks out os.Stdout.

type StdoutSetter added in v1.0.0

type StdoutSetter interface {
	SetStdout(*os.File)
}

StdoutSetter mocks out redirecting os.Stdout.

type SymlinksEvaluator

type SymlinksEvaluator interface {
	EvalSymlinks(path string) (string, error)
}

SymlinksEvaluator mocks out filepath.EvalSymlinks.

type UserHomeDir added in v1.1.0

type UserHomeDir interface {
	GetUserHome() (string, error)
}

UserHomeDir mocks out os.UserHomeDir.

type WorkingDirectory added in v1.1.0

type WorkingDirectory interface {
	GetWd() (string, error)
}

WorkingDirectory mocks out os.GetWd.

Jump to

Keyboard shortcuts

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