testutils

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertErrorMatch

func AssertErrorMatch(t *testing.T, err error, re *regexp.Regexp, msgAndArgs ...interface{}) bool

AssertErrorMatch fails the test t if err is nil or if its message does not match the provided regexp re

func AssertFileDoesNotExist

func AssertFileDoesNotExist(t *testing.T, path string, msgAndArgs ...interface{}) bool

AssertFileDoesNotExist failts the test t if path exists

func AssertFileExists

func AssertFileExists(t *testing.T, path string, msgAndArgs ...interface{}) bool

AssertFileExists failts the test t if path does not exists

func AssertPanicsMatch

func AssertPanicsMatch(t *testing.T, fn func(), re *regexp.Regexp, msgAndArgs ...interface{}) bool

AssertPanicsMatch fails the test t if fn does not panic or if the panic message does not match the provided regexp re

func Measure

func Measure(fn func()) time.Duration

Measure executes fn and returns the time taken for it to finish

Types

type Sandbox

type Sandbox struct {
	sync.RWMutex
	// Root of the sandbox
	Root string
	// contains filtered or unexported fields
}

Sandbox allows manipulating files and directories with paths sandboxed into the Root directory

func NewSandbox

func NewSandbox(args ...string) *Sandbox

NewSandbox returns a new sandbox with the configured root or a random temporary one if none is provided

func (*Sandbox) Cleanup

func (sb *Sandbox) Cleanup() error

Cleanup removes all the resources created by the sandbox

func (*Sandbox) ContainsPath

func (sb *Sandbox) ContainsPath(path string) bool

ContainsPath returns true if path is contained inside the sandbox and false otherwise. This function does not check for the existence of the file, just checks if the path is contained in the sanbox root

func (*Sandbox) Mkdir

func (sb *Sandbox) Mkdir(p string, mode os.FileMode) (string, error)

Mkdir creates a directory inside the sandbox

func (*Sandbox) Normalize

func (sb *Sandbox) Normalize(path string) string

Normalize returns the fully normalized version of path, including the Root prefix

func (sb *Sandbox) Symlink(oldname, newname string) (string, error)

Symlink creates a symlink inside the sandbox

func (*Sandbox) TempFile

func (sb *Sandbox) TempFile(args ...string) string

TempFile returns a temporary non-existent file. An optional file tail can be provided

func (*Sandbox) Touch

func (sb *Sandbox) Touch(file string) string

Touch touches a file inside the sandbox

func (*Sandbox) Track

func (sb *Sandbox) Track(p string)

Track registers a path as a temporary one to be deleted on cleanup

func (*Sandbox) Write

func (sb *Sandbox) Write(path string, data string) (string, error)

Write writes data into the file pointed by path. This is a convenience wrapper around WriteFile

func (*Sandbox) WriteFile

func (sb *Sandbox) WriteFile(path string, data []byte, mode os.FileMode) (string, error)

WriteFile writes a set of bytes (data) into the file pointed by path and with the specified mode

Jump to

Keyboard shortcuts

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