Documentation ¶
Overview ¶
Package testcontext implements convenience context for testing.
Index ¶
- Variables
- type Context
- func (ctx *Context) Check(fn func() error)
- func (ctx *Context) Cleanup()
- func (ctx *Context) Compile(pkg string, preArgs ...string) string
- func (ctx *Context) CompileAt(workDir, pkg string, preArgs ...string) string
- func (ctx *Context) CompileWithLDFlagsX(pkg string, ldFlagsX map[string]string) string
- func (ctx *Context) Dir(elem ...string) string
- func (ctx *Context) File(elem ...string) string
- func (ctx *Context) Go(fn func() error)
- func (ctx *Context) StackTrace() string
- func (ctx *Context) Wait()
- type TB
Constants ¶
This section is empty.
Variables ¶
var DefaultTimeout = 3 * time.Minute
DefaultTimeout is the default timeout used by new context.
Functions ¶
This section is empty.
Types ¶
type Context ¶
Context is a context that has utility methods for testing and waiting for asynchronous errors.
func NewWithContext ¶
NewWithContext creates a new test context with a parent context.
func NewWithContextAndTimeout ¶
NewWithContextAndTimeout creates a new test context with a given timeout and the parent context.
func NewWithTimeout ¶
NewWithTimeout creates a new test context with a given timeout.
func (*Context) Cleanup ¶
func (ctx *Context) Cleanup()
Cleanup waits everything to be completed, checks errors and goroutines which haven't ended and tries to cleanup directories.
Since Go 1.14 this method isn't required anymore because the https://pkg.go.dev/testing#T.Cleanup addition.
func (*Context) CompileAt ¶
CompileAt compiles the specified package and returns the executable name.
func (*Context) CompileWithLDFlagsX ¶
CompileWithLDFlagsX compiles the specified package with the -ldflags flag set to "-s -w [-X <key>=<value>,...]" given the passed map and returns the executable name.
func (*Context) Dir ¶
Dir creates a subdirectory inside temp joining any number of path elements into a single path and return its absolute path.
func (*Context) File ¶
File returns a filepath inside a temp directory joining any number of path elements into a single path and returns its absolute path.
func (*Context) StackTrace ¶
StackTrace returns stack trace about the goroutines that are related to this Context.