Documentation
¶
Index ¶
- func ContextWithEnvironmentGetter(ctx context.Context, getter EnvironmentGetter) context.Context
- type DirectoryOverrideEnvironmentGetter
- func (d *DirectoryOverrideEnvironmentGetter) Abs(path string) (string, error)
- func (d *DirectoryOverrideEnvironmentGetter) Getenv(key string) string
- func (d *DirectoryOverrideEnvironmentGetter) Getwd() (string, error)
- func (d *DirectoryOverrideEnvironmentGetter) ReadFile(name string) ([]byte, error)
- func (d *DirectoryOverrideEnvironmentGetter) Stat(name string) (fs.FileInfo, error)
- type EnvironmentGetter
- type MapEnvironmentGetter
- func (m MapEnvironmentGetter) Abs(path string) (string, error)
- func (m MapEnvironmentGetter) Getenv(key string) string
- func (m MapEnvironmentGetter) Getwd() (string, error)
- func (m MapEnvironmentGetter) ReadFile(name string) ([]byte, error)
- func (m MapEnvironmentGetter) Stat(name string) (fs.FileInfo, error)
- type MockEnvironmentOption
- func WithEnv(env map[string]string) MockEnvironmentOption
- func WithFS(fs map[string]MockFile) MockEnvironmentOption
- func WithFile(path string, content []byte) MockEnvironmentOption
- func WithFileInfo(path string, content []byte, info fs.FileInfo) MockEnvironmentOption
- func WithFileString(path string, content string) MockEnvironmentOption
- func WithWorkingDirectory(wd string) MockEnvironmentOption
- type MockFile
- type SystemEnvironmentGetter
- func (s SystemEnvironmentGetter) Abs(path string) (string, error)
- func (s SystemEnvironmentGetter) Getenv(key string) string
- func (s SystemEnvironmentGetter) Getwd() (string, error)
- func (s SystemEnvironmentGetter) ReadFile(name string) ([]byte, error)
- func (s SystemEnvironmentGetter) Stat(name string) (fs.FileInfo, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithEnvironmentGetter ¶
func ContextWithEnvironmentGetter(ctx context.Context, getter EnvironmentGetter) context.Context
ContextWithEnvironmentGetter returns a new context with the given EnvironmentGetter
Types ¶
type DirectoryOverrideEnvironmentGetter ¶
type DirectoryOverrideEnvironmentGetter struct {
EnvironmentGetter
// contains filtered or unexported fields
}
DirectoryOverrideEnvironmentGetter wraps another EnvironmentGetter but overrides the working directory
func NewDirectoryOverrideEnvironmentGetter ¶
func NewDirectoryOverrideEnvironmentGetter(base EnvironmentGetter, dir string) *DirectoryOverrideEnvironmentGetter
NewDirectoryOverrideEnvironmentGetter creates a new getter with an overridden working directory
func (*DirectoryOverrideEnvironmentGetter) Abs ¶
func (d *DirectoryOverrideEnvironmentGetter) Abs(path string) (string, error)
func (*DirectoryOverrideEnvironmentGetter) Getenv ¶
func (d *DirectoryOverrideEnvironmentGetter) Getenv(key string) string
func (*DirectoryOverrideEnvironmentGetter) Getwd ¶
func (d *DirectoryOverrideEnvironmentGetter) Getwd() (string, error)
type EnvironmentGetter ¶
type EnvironmentGetter interface {
Getenv(key string) string
Getwd() (string, error)
Abs(path string) (string, error)
Stat(name string) (fs.FileInfo, error)
ReadFile(name string) ([]byte, error)
}
EnvironmentGetter is an interface for getting environment variables and the current working directory. This can help with testing by making otherwise impure functions pure.
func EnvironmentGetterFromContext ¶
func EnvironmentGetterFromContext(ctx context.Context) EnvironmentGetter
EnvironmentGetterFromContext retrieves the EnvironmentGetter from the context, returning the default system implementation if none is found
type MapEnvironmentGetter ¶
type MapEnvironmentGetter struct {
EnvironmentGetter
Env map[string]string
Wd string
FS map[string]MockFile
}
MapEnvironmentGetter provides a mock implementation for testing
func NewMockEnvironmentGetter ¶
func NewMockEnvironmentGetter(opts ...MockEnvironmentOption) *MapEnvironmentGetter
NewMockEnvironmentGetter creates a new mock environment getter with options
func (MapEnvironmentGetter) Getenv ¶
func (m MapEnvironmentGetter) Getenv(key string) string
func (MapEnvironmentGetter) Getwd ¶
func (m MapEnvironmentGetter) Getwd() (string, error)
type MockEnvironmentOption ¶
type MockEnvironmentOption func(*MapEnvironmentGetter)
MockEnvironmentOption is a functional option for configuring MapEnvironmentGetter
func WithEnv ¶
func WithEnv(env map[string]string) MockEnvironmentOption
WithEnv sets environment variables for the mock
func WithFS ¶
func WithFS(fs map[string]MockFile) MockEnvironmentOption
WithFS provides a complete mock filesystem
func WithFile ¶
func WithFile(path string, content []byte) MockEnvironmentOption
WithFile adds a single file to the mock filesystem
func WithFileInfo ¶
func WithFileInfo(path string, content []byte, info fs.FileInfo) MockEnvironmentOption
WithFileInfo adds a file with custom FileInfo to the mock filesystem
func WithFileString ¶
func WithFileString(path string, content string) MockEnvironmentOption
WithFileString adds a single file to the mock filesystem with string content
func WithWorkingDirectory ¶
func WithWorkingDirectory(wd string) MockEnvironmentOption
WithWorkingDirectory sets the working directory for the mock
type SystemEnvironmentGetter ¶
type SystemEnvironmentGetter struct {
EnvironmentGetter
}
SystemEnvironmentGetter provides direct access to the system's environment and filesystem operations.
func (SystemEnvironmentGetter) Abs ¶
func (s SystemEnvironmentGetter) Abs(path string) (string, error)
func (SystemEnvironmentGetter) Getenv ¶
func (s SystemEnvironmentGetter) Getenv(key string) string
func (SystemEnvironmentGetter) Getwd ¶
func (s SystemEnvironmentGetter) Getwd() (string, error)