Documentation ¶
Overview ¶
Package helpers (github.com/launchdarkly/go-test-helpers) contains miscellaneous convenience functions for use in test code.
Index ¶
- func BoolPtr(b bool) *bool
- func FilePathExists(path string) bool
- func Float64Ptr(n float64) *float64
- func IntPtr(n int) *int
- func ReadWithTimeout(r io.Reader, n int, timeout time.Duration) []byte
- func StrPtr(s string) *string
- func Uint64Ptr(n uint64) *uint64
- func WithCloser(closeableObject io.Closer, action func())
- func WithTempFile(f func(string))
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BoolPtr ¶
BoolPtr returns a pointer to a bool value. This is useful within expressions where the value is a literal.
func FilePathExists ¶
FilePathExists is simply a shortcut for using os.Stat to check for a file's or directory's existence.
func Float64Ptr ¶
Float64Ptr returns a pointer to an float64 value. This is useful within expressions where the value is a literal.
func IntPtr ¶
IntPtr returns a pointer to an int value. This is useful within expressions where the value is a literal.
func ReadWithTimeout ¶
ReadWithTimeout reads data until it gets the desired number of bytes or times out.
This is an inefficient implementation that should only be used in tests.
func StrPtr ¶
StrPtr returns a pointer to a string value. This is useful within expressions where the value is a literal.
func Uint64Ptr ¶
Uint64Ptr returns a pointer to a uint64 value. This is useful within expressions where the value is a literal.
func WithCloser ¶
WithCloser executes a function and ensures that the given object's Close() method is always called afterward.
This is simply a way to get more specific control over an object's lifetime than using defer. A test function may wish to ensure that an object is closed before some subsequent actions are taken, rather than at the end of the entire test.
If closing the object fails, an error is logged.
func WithTempFile ¶
func WithTempFile(f func(string))
WithTempFile creates a temporary file, passes its name to the given function, then ensures that the file is deleted.
If for any reason it is not possible to create the file, a panic is raised since the test code cannot continue.
If deletion of the file fails (assuming it has not already been deleted) then an error is logged, but there is no panic.
helpers.WithTempFile(func(path string) { DoSomethingWithTempFile(path) }) // the file is deleted at the end of this block
Types ¶
This section is empty.
Directories ¶
Path | Synopsis |
---|---|
Package httphelpers contains convenience tools for testing HTTP client code.
|
Package httphelpers contains convenience tools for testing HTTP client code. |
Package jsonhelpers contains general-purpose functions for manipulating JSON.
|
Package jsonhelpers contains general-purpose functions for manipulating JSON. |
Package ldservices provides HTTP handlers that simulate the behavior of LaunchDarkly service endpoints.
|
Package ldservices provides HTTP handlers that simulate the behavior of LaunchDarkly service endpoints. |
Package matchers provides a flexible test assertion API similar to Java's Hamcrest.
|
Package matchers provides a flexible test assertion API similar to Java's Hamcrest. |
Package testbox provides the ability to run test logic that uses a subset of Go's testing.T methods either inside or outside the regular testing environment.
|
Package testbox provides the ability to run test logic that uses a subset of Go's testing.T methods either inside or outside the regular testing environment. |