testutil

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2021 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(t *testing.T, path string) string

func CheckContains

func CheckContains(t *testing.T, expected, actual string)

func CheckDeepEqual

func CheckDeepEqual(t *testing.T, expected, actual interface{}, opts ...cmp.Option)

func CheckError

func CheckError(t *testing.T, shouldErr bool, err error)

func CheckErrorAndDeepEqual

func CheckErrorAndDeepEqual(t *testing.T, shouldErr bool, err error, expected, actual interface{}, opts ...cmp.Option)

func CheckNotContains

func CheckNotContains(t *testing.T, excluded, actual string)

func EnsureTestPanicked

func EnsureTestPanicked(t *testing.T)

func Run

func Run(t *testing.T, name string, f func(t *T))

func ServeFile

func ServeFile(t *testing.T, content []byte) string

ServeFile serves a file with http. Returns the url to the file and a teardown function that should be called to properly stop the server.

func SetupFakeWatcher

func SetupFakeWatcher(w watch.Interface) func(a fake_testing.Action) (handled bool, ret watch.Interface, err error)

SetupFakeWatcher helps set up a fake Kubernetes watcher

func TempFile

func TempFile(t *testing.T, prefix string, content []byte) string

TempFile creates a temporary file with a given content. Returns the file name and a teardown function that should be called to properly delete the file.

Types

type ForTester

type ForTester interface {
	ForTest(t *testing.T)
}

type T

type T struct {
	*testing.T
}

func (*T) Chdir

func (t *T) Chdir(dir string)

func (*T) CheckContains

func (t *T) CheckContains(expected, actual string)

func (*T) CheckDeepEqual

func (t *T) CheckDeepEqual(expected, actual interface{}, opts ...cmp.Option)

func (*T) CheckEmpty

func (t *T) CheckEmpty(actual interface{})

func (*T) CheckError

func (t *T) CheckError(shouldErr bool, err error)

func (*T) CheckErrorAndDeepEqual

func (t *T) CheckErrorAndDeepEqual(shouldErr bool, err error, expected, actual interface{}, opts ...cmp.Option)

func (*T) CheckErrorContains

func (t *T) CheckErrorContains(message string, err error)

CheckErrorContains checks that an error is not nil and contains a given message.

func (*T) CheckFalse

func (t *T) CheckFalse(actual bool)

func (*T) CheckMatches

func (t *T) CheckMatches(pattern, actual string)

func (*T) CheckNil

func (t *T) CheckNil(actual interface{})

func (*T) CheckNotNil

func (t *T) CheckNotNil(actual interface{})

func (*T) CheckTrue

func (t *T) CheckTrue(actual bool)

func (*T) NewTempDir

func (t *T) NewTempDir() *TempDir

func (*T) Override

func (t *T) Override(dest, tmp interface{})

func (*T) SetArgs

func (t *T) SetArgs(args []string)

SetArgs override os.Args for the duration of a test.

func (*T) SetEnvs

func (t *T) SetEnvs(envs map[string]string)

SetEnvs takes a map of key values to set using os.Setenv and returns a function that can be called to reset the envs to their previous values, or unset envs where previously unset

func (*T) SetStdin

func (t *T) SetStdin(content []byte)

SetStdin replaces os.Stdin with a given content.

func (*T) TempFile

func (t *T) TempFile(prefix string, content []byte) string

type TempDir

type TempDir struct {
	// contains filtered or unexported fields
}

TempDir offers actions on a temp directory.

func NewTempDir

func NewTempDir(t *testing.T) *TempDir

NewTempDir creates a temporary directory and a teardown function that should be called to properly delete the directory content.

func (*TempDir) Chdir

func (h *TempDir) Chdir() *TempDir

Chdir changes current directory to this temp directory.

func (*TempDir) Chtimes

func (h *TempDir) Chtimes(file string, t time.Time) *TempDir

Chtimes changes the times for a file in the temp directory.

func (*TempDir) Mkdir

func (h *TempDir) Mkdir(dir string) *TempDir

Mkdir makes a sub-directory in the temp directory.

func (*TempDir) Path

func (h *TempDir) Path(file string) string

Path returns the path to a file in the temp directory.

func (*TempDir) Paths

func (h *TempDir) Paths(files ...string) []string

Paths returns the paths to a list of files in the temp directory.

func (*TempDir) Remove

func (h *TempDir) Remove(file string) *TempDir

Remove deletes a file from the temp directory.

func (*TempDir) Rename

func (h *TempDir) Rename(oldName, newName string) *TempDir

Rename renames a file from oldname to newname

func (*TempDir) Root

func (h *TempDir) Root() string

Root returns the temp directory.

func (h *TempDir) Symlink(dst, src string) *TempDir

Symlink creates a symlink.

func (*TempDir) Touch

func (h *TempDir) Touch(files ...string) *TempDir

Touch creates a list of empty files in the temp directory.

func (*TempDir) Write

func (h *TempDir) Write(file string, content []byte) *TempDir

Write write content to a file in the temp directory.

func (*TempDir) WriteFiles

func (h *TempDir) WriteFiles(files map[string][]byte) *TempDir

WriteFiles write a list of files (path->content) in the temp directory.

func (*TempDir) WriteRandomFile

func (h *TempDir) WriteRandomFile(file string, size int) *TempDir

Jump to

Keyboard shortcuts

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