testing

package
v0.41.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearEnvs

func ClearEnvs(t *testing.T)

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

func FileExists(t *testing.T, filePath string) (bool, error)

FileExists checks whether file on the specified path exists

func Fromtemp

func Fromtemp(t *testing.T) func()

Fromtemp is like Mktemp, but does not bother returing the temp path.

func Mktemp

func Mktemp(t *testing.T) (string, func())

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

func RunGitServer(root string, t *testing.T) (url string)

RunGitServer starts serving git HTTP server and returns its address

func ServeRepo

func ServeRepo(name string, t *testing.T) string

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

func Using(t *testing.T, root string) func()

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

func WithExecutable(t *testing.T, name, goSrc string)

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.

func Within

func Within(t *testing.T, root string) func()

Within the given root creates the directory, CDs to it, and rturns a closure that when executed (intended in a defer) removes the given dirctory and returns the caller to the initial working directory. usage:

defer within(t, "somedir")()

Types

This section is empty.

Jump to

Keyboard shortcuts

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