From 49683c0c206e63e0a476a6577fcea7b2a0a1bd38 Mon Sep 17 00:00:00 2001 From: Bjoern Rabenstein Date: Thu, 27 Nov 2014 18:04:48 +0100 Subject: [PATCH] Avoid test flags in normal binary. Change-Id: If1fba813a73bf93ea5918dcda326e3ffa81a797d --- storage/local/test_helpers.go | 8 ++++++-- utility/test/directory.go | 14 +++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/storage/local/test_helpers.go b/storage/local/test_helpers.go index 7e4538387..91b1156c3 100644 --- a/storage/local/test_helpers.go +++ b/storage/local/test_helpers.go @@ -11,10 +11,14 @@ // See the License for the specific language governing permissions and // limitations under the License. +// NOTE ON FILENAME: Do not rename this file helpers_test.go (which might appear +// an obvious choice). We need NewTestStorage in tests outside of the local +// package, too. On the other hand, moving NewTestStorage in its own package +// would cause circular dependencies in the tests in packages local. + package local import ( - "testing" "time" "github.com/prometheus/prometheus/utility/test" @@ -33,7 +37,7 @@ func (t *testStorageCloser) Close() { // NewTestStorage creates a storage instance backed by files in a temporary // directory. The returned storage is already in serving state. Upon closing the // returned test.Closer, the temporary directory is cleaned up. -func NewTestStorage(t testing.TB) (Storage, test.Closer) { +func NewTestStorage(t test.T) (Storage, test.Closer) { directory := test.NewTemporaryDirectory("test_storage", t) o := &MemorySeriesStorageOptions{ MemoryChunks: 1000000, diff --git a/utility/test/directory.go b/utility/test/directory.go index 1572f74df..994439591 100644 --- a/utility/test/directory.go +++ b/utility/test/directory.go @@ -16,7 +16,6 @@ package test import ( "io/ioutil" "os" - "testing" ) const ( @@ -51,12 +50,21 @@ type ( // their interactions. temporaryDirectory struct { path string - tester testing.TB + tester T } callbackCloser struct { fn func() } + + // T implements the needed methods of testing.TB so that we do not need + // to actually import testing (which has the side affect of adding all + // the test flags, which we do not want in non-test binaries even if + // they make use of these utilities for some reason). + T interface { + Fatal(args ...interface{}) + Fatalf(format string, args ...interface{}) + } ) func (c nilCloser) Close() { @@ -90,7 +98,7 @@ func (t temporaryDirectory) Path() string { // NewTemporaryDirectory creates a new temporary directory for transient POSIX // activities. -func NewTemporaryDirectory(name string, t testing.TB) (handler TemporaryDirectory) { +func NewTemporaryDirectory(name string, t T) (handler TemporaryDirectory) { var ( directory string err error