envfs

package
v1.2.166 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

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 (*DirectoryOverrideEnvironmentGetter) Getenv

func (*DirectoryOverrideEnvironmentGetter) Getwd

func (*DirectoryOverrideEnvironmentGetter) ReadFile

func (d *DirectoryOverrideEnvironmentGetter) ReadFile(name string) ([]byte, error)

func (*DirectoryOverrideEnvironmentGetter) Stat

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) Abs

func (m MapEnvironmentGetter) Abs(path string) (string, error)

func (MapEnvironmentGetter) Getenv

func (m MapEnvironmentGetter) Getenv(key string) string

func (MapEnvironmentGetter) Getwd

func (m MapEnvironmentGetter) Getwd() (string, error)

func (MapEnvironmentGetter) ReadFile

func (m MapEnvironmentGetter) ReadFile(name string) ([]byte, error)

func (MapEnvironmentGetter) Stat

func (m MapEnvironmentGetter) Stat(name string) (fs.FileInfo, 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 MockFile

type MockFile struct {
	Content []byte
	Info    fs.FileInfo
}

MockFile represents a mocked file with content and optional file info

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)

func (SystemEnvironmentGetter) ReadFile

func (s SystemEnvironmentGetter) ReadFile(name string) ([]byte, error)

func (SystemEnvironmentGetter) Stat

Jump to

Keyboard shortcuts

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