Documentation ¶
Index ¶
- Variables
- func AssertChanNoReceive(t *testing.T, ch chan struct{}, name string, timeout time.Duration)
- func AssertChanReceive(t *testing.T, ch chan struct{}, name string, timeout time.Duration, ...)
- func Fatal(t Logger, args ...interface{})
- func Fatalf(l Logger, f string, args ...interface{})
- func RandomTestString(n int) string
- func RootTempDir(t *TestTool) string
- func SendWithCancel(w chan<- struct{}, done <-chan struct{})
- func TestEqual(t Logger, have, want interface{}, msg ...string)
- func TestExpectError(l Logger, err error, msg ...string)
- func TestExpectNonNil(t Logger, i interface{}, msg ...string)
- func TestExpectNonZeroLength(l Logger, size int)
- func TestExpectPanic(l Logger, f func(), msg string)
- func TestExpectSuccess(l Logger, err error, msg ...string)
- func TestExpectZeroLength(l Logger, size int)
- func TestFalse(t Logger, ans bool)
- func TestHttpGet(t Logger, url string, expectedReturnCode int) (string, int)
- func TestHttpGetTimeout(t Logger, url string, expectedReturnCode int, duration time.Duration) (string, int)
- func TestHttpPost(t Logger, url string, contentType string, body string, expectedReturnCode int) (string, int)
- func TestHttpPut(t Logger, url string, contentType string, body string, expectedReturnCode int) (string, int)
- func TestMatch(t Logger, have string, r *regexp.Regexp)
- func TestNotEqual(t Logger, have, want interface{}, msg ...string)
- func TestNotMatch(t Logger, have string, r *regexp.Regexp)
- func TestRequiresRoot(l Logger)
- func TestTrue(t Logger, ans bool)
- func Timeout(l Logger, timeout, sleep time.Duration, f func() bool)
- type Backtracer
- type Logger
- type TestData
- type TestTool
- func (tt *TestTool) AddTestFinalizer(f func())
- func (tt *TestTool) FinishTest()
- func (tt *TestTool) TempDir() string
- func (tt *TestTool) TempDirMode(mode os.FileMode) string
- func (tt *TestTool) TempFile() string
- func (tt *TestTool) TempFileMode(mode os.FileMode) string
- func (tt *TestTool) WriteTempFile(contents string) string
- func (tt *TestTool) WriteTempFileMode(contents string, mode os.FileMode) string
Constants ¶
This section is empty.
Variables ¶
var TestLogFile string = ""
If a -log or log is provided with an path to a directory then that path is available in this variable. This is a helper for tests that wish to log. An empty string indicates the path was not set. The value is set only to allow callers to make use of in their tests. There are no other side effects.
Functions ¶
func AssertChanNoReceive ¶
AssertChanNoreceive ensures that the specified channel never received a message. AssertChanNoReceive requires a name of the function that should not write to the channel in order to provide a useful error message.
func AssertChanReceive ¶
func AssertChanReceive( t *testing.T, ch chan struct{}, name string, timeout time.Duration, numSends int, )
AssertChanReceive ensures that the given channel received the specified number of messages. The supplied timeout specifies the timeout on each expected read. It is not a cumulative timeout for all reads. AssertChanReceive requires a name of the function that should write to the channel in order to provide a useful error message.
func Fatal ¶
func Fatal(t Logger, args ...interface{})
Fatal fails the test with a simple format for the message.
func Fatalf ¶
Fatalf wraps Fatalf in order to provide a functional stack trace on failures rather than just a line number of the failing check. This helps if you have a test that fails in a loop since it will show the path to get there as well as the error directly.
func RandomTestString ¶
RandomTestString generates a random test string from only upper and lower case letters.
func RootTempDir ¶
RootTempDir creates a directory that will exist until the process running the tests exits.
func SendWithCancel ¶
func SendWithCancel(w chan<- struct{}, done <-chan struct{})
SendWithCancel expects a channel to write a signal to, and also a channel that indicates when the signal listener is no longer listening.
func TestExpectError ¶
TestExpectError calls Fatal if err is nil.
func TestExpectNonNil ¶
func TestExpectNonZeroLength ¶
TestExpectNonZeroLength fails the test if the given value is zero.
func TestExpectPanic ¶
TestExpectPanic verifies that a panic is called with the expected msg.
func TestExpectSuccess ¶
TestExpectSuccess fails the test if err is not nil and fails the test and output the reason for the failure as the err argument the same as Fatalf. If err implements the BackTracer interface a backtrace will also be displayed.
func TestExpectZeroLength ¶
TestExpectNonZeroLength fails the test if the given value is not zero.
func TestHttpGet ¶
Test an HTTP GET to the given URL. If expectedReturnCode is a value other than -1, the test will fail if the response status code doesn't match the exptected code. Method returns the string value of the response body and the status code.
func TestHttpGetTimeout ¶
func TestHttpGetTimeout(t Logger, url string, expectedReturnCode int, duration time.Duration) (string, int)
Test an HTTP GET to the given URL for the amount of time specified in duration. This will retry with multiple requests until one is successful or it has taken longer than the duration. If expectedReturnCode is a value other than -1, the test will fail if the response status code doesn't match the exptected code. Method returns the string value of the response body and the status code.
func TestHttpPost ¶
func TestHttpPost( t Logger, url string, contentType string, body string, expectedReturnCode int, ) (string, int)
Test an HTTP POST to the given URL, with the given content type and request body.. If expectedReturnCode is a value other than -1, the test will fail if the response status code doesn't match the exptected code. Method returns the string value of the response body and the status code.
func TestHttpPut ¶
func TestHttpPut( t Logger, url string, contentType string, body string, expectedReturnCode int, ) (string, int)
Test an HTTP PUT to the given URL, with the given content type and request body.. If expectedReturnCode is a value other than -1, the test will fail if the response status code doesn't match the exptected code. Method returns the string value of the response body and the status code.
func TestNotEqual ¶
func TestRequiresRoot ¶
func TestRequiresRoot(l Logger)
TestRequiresRoot is called to require that your test is run as root. NOTICE: this does not cause the test to FAIL. This seems like the most sane thing to do based on the shortcomings of Go's test utilities.
As an added feature this function will append all skipped test names into the file name specified in the environment variable:
$SKIPPED_ROOT_TESTS_FILE
Types ¶
type Backtracer ¶
type Backtracer interface {
Backtrace() []string
}
Backtracer is an interface that provies additional information to be displayed using the TestExpectSuccess() functions. For an example see BackError in the apcera/cfg package.
type Logger ¶
type Logger interface { Error(args ...interface{}) Errorf(format string, args ...interface{}) Failed() bool Fatal(args ...interface{}) Fatalf(format string, args ...interface{}) Skip(args ...interface{}) Skipf(format string, args ...interface{}) Log(args ...interface{}) Logf(format string, args ...interface{}) }
Logger is a common interface that can be used to allow testing.B and testing.T objects to be passed to the same function.
type TestData ¶
func GetTestData ¶
GetTestData goes through the call stack of the current goroutine and creates a ordered set of strings for the files, function names, and line numbers then adds this data to the error message.
type TestTool ¶
type TestTool struct { testing.TB // Stores output from the logging system so it can be written only if // the test actually fails. LogBuffer *unittest.LogBuffer // This is a list of functions that will be run on test completion. Having // this allows us to clean up temporary directories or files after the // test is done which is a huge win. Finalizers []func() // Parameters contains test-specific caches of data. Parameters map[string]interface{} RandomTestString string PackageHash string *TestData }
TestTool type allows for parallel tests.
func StartTest ¶
StartTest should be called at the start of a test to setup all the various state bits that are needed.
func (*TestTool) AddTestFinalizer ¶
func (tt *TestTool) AddTestFinalizer(f func())
AddTestFinalizer adds a function to be called once the test finishes.
func (*TestTool) FinishTest ¶
func (tt *TestTool) FinishTest()
FinishTest is called as a defer to a test in order to clean up after a test run. All tests in this module should call this function as a defer right after calling StartTest()
func (*TestTool) TempDirMode ¶
TempDirMode makes a temporary directory with the given mode.
func (*TestTool) TempFile ¶
TempFile allocate a temporary file and ensures that it gets cleaned up when the test is completed.
func (*TestTool) TempFileMode ¶
TempFileMode writes a temp file with the given mode.
func (*TestTool) WriteTempFile ¶
WriteTempFile writes contents to a temporary file, sets up a Finalizer to remove the file once the test is complete, and then returns the newly created filename to the caller.