Back to godoc.org
gotest.tools / env

Package env

v1.4.0
Latest Go to latest

The latest major version is v3.

Published: Mar 21, 2018 | License: Apache-2.0 | Module: gotest.tools

Overview

Package env provides functions to test code that read environment variables or the current working directory.

Index

Examples

func ChangeWorkingDir

func ChangeWorkingDir(t assert.TestingT, dir string) func()

ChangeWorkingDir to the directory, and return a function which restores the previous working directory.

func Patch

func Patch(t assert.TestingT, key, value string) func()

Patch changes the value of an environment variable, and returns a function which will reset the the value of that variable back to the previous state.

Example

Patch an environment variable and defer to return to the previous state

Code:

defer Patch(t, "PATH", "/custom/path")()

func PatchAll

func PatchAll(t assert.TestingT, env map[string]string) func()

PatchAll sets the environment to env, and returns a function which will reset the environment back to the previous state.

Example

Patch all environment variables

Code:

defer PatchAll(t, map[string]string{
	"ONE": "FOO",
	"TWO": "BAR",
})()

func ToMap

func ToMap(env []string) map[string]string

ToMap takes a list of strings in the format returned by os.Environ() and returns a mapping of keys to values.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier