environments

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: BSD-3-Clause Imports: 5 Imported by: 0

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

func NewTempDir(assert *asserts.Asserts) *TempDir

NewTempDir creates a new temporary directory usable for direct usage or further subdirectories.

func (*TempDir) Mkdir

func (td *TempDir) Mkdir(name ...string) string

Mkdir creates a potentially nested directory inside the temporary directory.

func (*TempDir) Restore

func (td *TempDir) Restore()

Restore deletes the temporary directory and all contents.

func (*TempDir) String

func (td *TempDir) String() string

String returns 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

func NewVariables(assert *asserts.Asserts) *Variables

NewVariables create a new changer for environment variables.

func (*Variables) Restore

func (v *Variables) Restore()

Restore resets all changed environment variables

func (*Variables) Set

func (v *Variables) Set(key, value string)

Set sets an environment variable to a new value.

func (*Variables) Unset

func (v *Variables) Unset(key string)

Unset unsets an environment variable.

Jump to

Keyboard shortcuts

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