osutil

package
v11.1.4-modfix Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Env

type Env interface {
	Setenv(key, value string) error
	Getenv(key string) string
}

Env collects global functions from standard package "os" that are related to environment variables. This allows abstracting code and provides a way to concurrently test code that needs access to these shared resources.

type MapEnv

type MapEnv map[string]string

MapEnv is a fake implementing Env interface. It is purposefully not concurrency-safe, so if your tests using it panic due to concurrent map access, then you need to fix a data race in your code. This is because environment variables are globals to a process, so you should be properly synchronizing access to them (e.g. with a mutex).

func (MapEnv) Getenv

func (m MapEnv) Getenv(key string) string

func (MapEnv) Setenv

func (m MapEnv) Setenv(key, value string) error

type RealEnv

type RealEnv struct{}

RealEnv implements Env interface by calling the actual global functions in package "os". This should be used by default anywhere that an Env is expected, and use MapEnv instead in your unit tests.

func (RealEnv) Getenv

func (RealEnv) Getenv(key string) string

func (RealEnv) Setenv

func (RealEnv) Setenv(key, value string) error

Jump to

Keyboard shortcuts

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