Avoid test flags in normal binary.

Change-Id: If1fba813a73bf93ea5918dcda326e3ffa81a797d
This commit is contained in:
Bjoern Rabenstein 2014-11-27 18:04:48 +01:00
parent ea86f7e8f8
commit 49683c0c20
2 changed files with 17 additions and 5 deletions

View file

@ -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,

View file

@ -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