Documentation ¶
Overview ¶
Package environments helps providing environments for unit tests. Here you can manipulate environment variables or create temporary directories to be used in tests and cleared afterwards.
For web applications there's the web asserter allowing to (a) run tests against own http.Handler and http.HandlerFunc as well as (b) act as a mock for own clients using HTTP. Included request and response types simplify most usual access.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TempDir ¶
type TempDir struct {
// contains filtered or unexported fields
}
TempDir represents a temporary directory and possible subdirectories for testing purposes. It simply is created with
assert := asserts.NewTesting(t, asserts.FailContinue) td := environments.NewTempDir(assert) defer td.Restore() tdName := td.String() subName:= td.Mkdir("my", "sub", "directory")
The deferred Restore() removes the temporary directory with all contents.
func NewTempDir ¶
NewTempDir creates a new temporary directory usable for direct usage or further subdirectories.
func (*TempDir) Mkdir ¶
Mkdir creates a potentially nested directory inside the temporary directory.
type Variables ¶
type Variables struct {
// contains filtered or unexported fields
}
Variables allows to change and restore environment variables. The same variable can be set multiple times. Simply do
assert := asserts.NewTesting(t, asserts.FailContinue) ev := environments.NewVariables(assert) defer ev.Restore() ev.Set("MY_VAR", myValue) ... ev.Set("MY_VAR", anotherValue)
The deferred Restore() resets to the original values.
func NewVariables ¶
NewVariables create a new changer for environment variables.
func (*Variables) Restore ¶
func (v *Variables) Restore()
Restore resets all changed environment variables