os

package
v0.2.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2025 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

This package provides an interface to functions and structs in the standard os package to facilitate mocking.

Index

Constants

View Source
const (
	O_RDONLY = os.O_RDONLY
	O_WRONLY = os.O_WRONLY
	O_RDWR   = os.O_RDWR

	O_APPEND = os.O_APPEND
	O_CREATE = os.O_CREATE
	O_EXCL   = os.O_EXCL
	O_SYNC   = os.O_SYNC
	O_TRUNC  = os.O_TRUNC

	SEEK_SET = os.SEEK_SET
	SEEK_CUR = os.SEEK_CUR
	SEEK_END = os.SEEK_END

	PathSeparator     = os.PathSeparator
	PathListSeparator = os.PathListSeparator

	DevNull = os.DevNull
)

Variables

View Source
var (
	ModeFile       = fs.ModeFile
	ModeDir        = fs.ModeDir
	ModeAppend     = fs.ModeAppend
	ModeExclusive  = fs.ModeExclusive
	ModeTemporary  = fs.ModeTemporary
	ModeSymlink    = fs.ModeSymlink
	ModeDevice     = fs.ModeDevice
	ModeNamedPipe  = fs.ModeNamedPipe
	ModeSocket     = fs.ModeSocket
	ModeSetuid     = fs.ModeSetuid
	ModeSetgid     = fs.ModeSetgid
	ModeCharDevice = fs.ModeCharDevice
	ModeSticky     = fs.ModeSticky
	ModeIrregular  = fs.ModeIrregular

	ModePerm = os.ModePerm
)
View Source
var (
	ErrInvalid = os.ErrInvalid

	ErrPermission = os.ErrPermission
	ErrExist      = os.ErrExist
	ErrNotExist   = os.ErrNotExist
	ErrClosed     = os.ErrClosed

	ErrNoDeadline       = os.ErrNoDeadline
	ErrDeadlineExceeded = os.ErrDeadlineExceeded

	ErrProcessDone = os.ErrProcessDone
)

Functions

func WrapFile added in v0.2.1

func WrapFile(f *os.File) fileFacade

This is a basic constructor, but I didn't want to name it New* because that might imply that it actually creates a file.

func WrapProcess added in v0.2.1

func WrapProcess(p *os.Process) processFacade

Types

type DirEntry

type DirEntry = fs.DirEntry

type File

type File interface {
	Chdir() error
	Chmod(FileMode) error
	Chown(int, int) error
	Close() error
	Fd() uintptr
	Name() string
	Read([]byte) (int, error)
	ReadAt([]byte, int64) (int, error)
	ReadDir(int) ([]DirEntry, error)
	ReadFrom(io.Reader) (int64, error)
	Readdir(int) ([]FileInfo, error)
	Readdirnames(int) ([]string, error)
	Seek(int64, int) (int64, error)
	SetDeadline(time.Time) error
	SetReadDeadline(time.Time) error
	SetWriteDeadline(time.Time) error
	Stat() (FileInfo, error)
	Sync() error
	SyscallConn() (syscall.RawConn, error)
	Truncate(int64) error
	Write([]byte) (int, error)
	WriteAt([]byte, int64) (int, error)
	WriteString(string) (int, error)
	WriteTo(io.Writer) (int64, error)
}

type FileInfo

type FileInfo = fs.FileInfo

type FileMode

type FileMode = fs.FileMode

type LinkError

type LinkError = os.LinkError

type OS

type OS interface {
	// Access to global variables:
	Stdin() File
	Stderr() File
	Stdout() File

	Args() []string

	// Functions:
	Chdir(string) error
	Chmod(string, FileMode) error
	Chown(string, int, int) error
	Chtimes(string, time.Time, time.Time) error
	Clearenv()
	CopyFS(string, fs.FS) error
	DirFS(string) fs.FS
	Environ() []string
	Executable() (string, error)
	Exit(int)
	Expand(string, func(string) string) string
	ExpandEnv(string) string
	Getegid() int
	Getenv(string) string
	Geteuid() int
	Getgid() int
	Getgroups() ([]int, error)
	Getpagesize() int
	Getpid() int
	Getppid() int
	Getuid() int
	Getwd() (string, error)
	Hostname() (string, error)
	IsExist(error) bool    // Deprecated
	IsNotExist(error) bool // Deprecated
	IsPathSeparator(uint8) bool
	IsPermission(error) bool // Deprecated
	IsTimeout(error) bool    // Deprecated
	Lchown(string, int, int) error
	Link(string, string) error
	LookupEnv(string) (string, bool)
	Mkdir(string, FileMode) error
	MkdirAll(string, FileMode) error
	MkdirTemp(string, string) (string, error)
	NewSyscallError(string, error) error
	Pipe() (File, File, error)
	ReadFile(string) ([]byte, error)
	Readlink(string) (string, error)
	Remove(string) error
	RemoveAll(string) error
	Rename(string, string) error
	SameFile(FileInfo, FileInfo) bool
	Setenv(string, string) error
	Symlink(string, string) error
	TempDir() string
	Truncate(string, int64) error
	Unsetenv(string) error
	UserCacheDir() (string, error)
	UserConfigDir() (string, error)
	UserHomeDir() (string, error)
	WriteFile(string, []byte, FileMode) error

	// DirEntry constructors
	ReadDir(string) ([]DirEntry, error)

	// File constructors
	Create(string) (File, error)
	CreateTemp(string, string) (File, error)
	NewFile(uintptr, string) File
	Open(string) (File, error)
	OpenFile(string, int, FileMode) (File, error)
	OpenInRoot(string, string) (File, error)

	// FileInfo constructors
	Lstat(string) (FileInfo, error)
	Stat(string) (FileInfo, error)

	// Process constructors
	FindProcess(int) (Process, error)
	StartProcess(string, []string, *ProcAttr) (Process, error)

	// Root constructors
	OpenRoot(string) (Root, error)
}

func NewOS

func NewOS() OS

type PathError

type PathError = os.PathError

type ProcAttr

type ProcAttr = os.ProcAttr

type Process

type Process interface {
	PID() int

	Kill() error
	Release() error
	Signal(Signal) error
	Wait() (*ProcessState, error)

	// Return the underlying process object
	Nub() *os.Process
}

type ProcessState

type ProcessState = os.ProcessState

type Root

type Root interface {
	Close() error
	Create(string) (File, error)
	FS() fs.FS
	Lstat(string) (FileInfo, error)
	Mkdir(string, FileMode) error
	Name() string
	Open(string) (File, error)
	OpenFile(string, int, FileMode) (File, error)
	OpenRoot(string) (Root, error)
	Remove(string) error
	Stat(string) (FileInfo, error)

	Nub() *os.Root
}

type Signal

type Signal = os.Signal

type SyscallError

type SyscallError = os.SyscallError

Directories

Path Synopsis
This package provides an interface to functions and structs in the standard os/exec package to facilitate mocking.
This package provides an interface to functions and structs in the standard os/exec package to facilitate mocking.

Jump to

Keyboard shortcuts

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