Documentation
¶
Overview ¶
package testing includes minor testing helpers.
These helpers include extensions to the testing nomenclature which exist to ease the development of tests for functions. It is mostly just syntactic sugar and closures for creating an removing test directories etc. It was originally included in each of the requisite testing packages, but since we use both private-access enabled tests (in the function package), as well as closed-box tests (in function_test package), and they are gradually increasing in size and complexity, the choice was made to choose a small dependency over a small amount of copying.
Another reason for including these in a separate locaiton is that they will have no tags such that no combination of tags can cause them to either be missing or interfere with eachother (a problem encountered with knative tooling which by default runs tests with all tags enabled simultaneously)
Index ¶
- func ClearEnvs(t *testing.T)
- func Cwd() (cwd string)
- func FileExists(t *testing.T, filePath string) (bool, error)
- func FromTempDirectory(t *testing.T) string
- func Fromtemp(t *testing.T) func()
- func Mktemp(t *testing.T) (string, func())
- func RunGitServer(root string, t *testing.T) (url string)
- func ServeRepo(name string, t *testing.T) string
- func Using(t *testing.T, root string) func()
- func WithExecutable(t *testing.T, name, goSrc string)
- func Within(t *testing.T, root string) func()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClearEnvs ¶
ClearEnvs sets all environment variables with the prefix of FUNC_ to empty (unsets) for the duration of the test t and is used when a test needs to completely clear func-releated envs prior to running.
func Cwd ¶
func Cwd() (cwd string)
Cwd returns the current working directory or panic if unable to determine.
func FileExists ¶
FileExists checks whether file on the specified path exists
func FromTempDirectory ¶ added in v0.42.0
FromTempDirectory moves the test into a new temporary directory and clears all known interfering environment variables. Returned is the path to the somewhat isolated test environment. Note that KUBECONFIG is also set to testdata/default_kubeconfig which can be used for tests which are explicitly checking logic which depends on kube context.
func Mktemp ¶
Mktemp creates a temporary directory, CDs the current processes (test) to said directory, and returns the path to said directory. Usage:
path, rm := Mktemp(t) defer rm() CWD is now 'path'
errors encountererd fail the current test.
func RunGitServer ¶
RunGitServer starts serving git HTTP server and returns its address
func ServeRepo ¶
ServeRepositry [name] from ./testdata/[name] returning URL at which the named repository is available. Must be called before any helpers which change test working directory such as fromTempDirectory(t)
func Using ¶
Using the given path, create it as a new directory and return a deferrable which will remove it. usage:
defer using(t, "testdata/example.com/someExampleTest")()
func WithExecutable ¶
WithExecutable creates an executable of the given name and source in a temp directory which is then added to PATH. Returned is a deferrable which will clean up both the script and PATH.
Types ¶
This section is empty.