Less verbose tests

Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
Daniel Nephin
2017-12-13 20:30:31 -05:00
parent 03bc5e974d
commit 49fffe8ec7
7 changed files with 13 additions and 12 deletions

View File

@@ -16,10 +16,9 @@ func init() {
flag.BoolVar(&rootEnabled, "test.root", false, "enable tests that require root")
}
// DumpDir will log out all of the contents of the provided directory to
// testing logger.
// DumpDir prints the contents of the directory to the testing logger.
//
// Use this in a defer statement within tests that may allocate and exercise a
// Use this in a defer statement from a test that may allocate and exercise a
// temporary directory. Immensely useful for sanity checking and debugging
// failing tests.
//
@@ -57,3 +56,11 @@ func DumpDir(t *testing.T, root string) {
t.Fatalf("error dumping directory: %v", err)
}
}
// DumpDirOnFailure prints the contents of the directory to the testing logger if
// the test has failed.
func DumpDirOnFailure(t *testing.T, root string) {
if t.Failed() {
DumpDir(t, root)
}
}